Skip to content

Instantly share code, notes, and snippets.

@antdking
Forked from mekhami/forms.py
Last active June 2, 2016 19:50
Show Gist options
  • Save antdking/58802e43f06b555b2955fe28c76324ea to your computer and use it in GitHub Desktop.
Save antdking/58802e43f06b555b2955fe28c76324ea to your computer and use it in GitHub Desktop.
class OrderForm(forms.ModelForm):
class Meta:
model = Order
fields = ['book_title', 'customer', 'internal_design', 'paid', 'start_date']
campaign = forms.ModelMultipleChoiceField(queryset=Campaign.objects.all())
def _save_m2m(self):
super()._save_m2m()
campaign = Campaign.objects.get(pk=self.cleaned_data['campaign'])
for producttype in campaign.product_types.all():
Product.objects.get_or_create(
order=self.instance,
product_type=producttype)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment