Answer the question
In order to leave comments, you need to log in
How to modify data before validation for m2m?
Django.
Surely this is googled, but I find it difficult to correctly formulate the question. For simplicity, I'll sketch out the code:
class A(models.model):
name = models.CharField()
class B(models.Model):
name = models.CharField
categories = models.ManyToMany(A)
class BForm(ModelForm):
class Meta:
model=B
class MyView(CreateView):
form = BForm
model = B
Answer the question
In order to leave comments, you need to log in
To save the form, you can do this:
Or like this (If the previous one does not work), but this is more a crutch:
def __init__(*args, **kwargs):
super(BForm, self).__init__(*args, **kwargs)
self.fields['category'].required = False
------WebKitFormBoundary9Vc3EoEBGNRCydFq
Content-Disposition: form-data; name="user_permissions"
43
------WebKitFormBoundary9Vc3EoEBGNRCydFq
Content-Disposition: form-data; name="user_permissions"
41
------WebKitFormBoundary9Vc3EoEBGNRCydFq
Content-Disposition: form-data; name="user_permissions"
49
------WebKitFormBoundary9Vc3EoEBGNRCydFq
Content-Disposition: form-data; name="user_permissions"
42
------WebKitFormBoundary9Vc3EoEBGNRCydFq
Content-Disposition: form-data; name="user_permissions"
40
------WebKitFormBoundary9Vc3EoEBGNRCydFq
Content-Disposition: form-data; name="user_permissions"
30
a[]=1
a[]=2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question