What are the steps to make a ModelForm work with a ManyToMany relationship with an intermediary model in Django?

前端 未结 5 1461
借酒劲吻你
借酒劲吻你 2020-12-23 11:46
  • I have a Client and Groupe Model.
  • A Client can be part of multiple groups.
  • Clients that are part of a gr
5条回答
  •  不知归路
    2020-12-23 12:35

    …
    if form.is_valid():
        client_mod = form.save(commit=False)
        client_mod.save()
        for groupe in form.cleaned_data.get('groupes'):
            clientgroupe = ClientGroupe(client=client_mod, groupe=groupe)
            clientgroupe.save()
        …
    

提交回复
热议问题