When I create a PotatoBatch item via my admin form, I want many Potato objects to be created.
Potato has a ForeignKey to PotatoBatch.
I made a PotatoBatchCreateForm that has an extra field, "number_of_potatoes". When I save this form, I want it to generate the correct number of potatoes for this batch.
I wanted to override my PotatoBatchCreateForm's save method like this :
def save(self, commit=True):
potato_batch = super().save() # save the potato_batch object in order to have an object id
number_of_potatoes = self.cleaned_data['number_of_potatoes']
for i in range(number_of_potatoes):
potato_batch.potato_set.create()
return potato_batch
But this fails with a 'PotatoBatchCreateForm' object has no attribute 'save_m2m' error.
How can I resolve this ?