I have the following model.py
:
class FinancialProduct(models.Model):
active = models.BooleanField(default=True)
name = models.CharField(max_length=20)
abbreviation = models.CharField(max_length=3)
table_name = models.CharField(max_length=5, choices=FP_TABLE_CHOICES)
businesses = models.ManyToManyField(Business)
And the following forms.py
:
class FinancialProductForm(ModelForm):
business = ModelMultipleChoiceField(widget=CheckboxSelectMultiple(),required=True)
class Meta:
model = FinancialProduct
def is_unique(self,latestFP):
if (self.cleaned_data['active'] == latestFP.active and
self.cleaned_data['name'].capitalize() == latestFP.name and
self.cleaned_data['acronym'].upper() == latestFP.acronym and
self.cleaned_data['table_name'] == latestFP.Table_name and
self.cleaned_data['business'] == latestFP.business):
return False
else:
return True
The is_unique()
functi开发者_运维问答on is called prior to saving but I am wondering how I can test to see if the many-to-many relationship has changed for business
. Any ideas?
EDIT
The form throws up an error as well when submitted due to the business m2m. Does it need additional processing before saving?
business
should be businesses
:)
精彩评论