Last active
June 2, 2016 19:30
-
-
Save mekhami/1db52cc201644eead3e628d6cee1eaf8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(self, commit=True): | |
campaign = Campaign.objects.get(pk=self.cleaned_data['campaign']) | |
# I need to create a Product object for each ProductType in campaign.producttypes. | |
# Product has a foreign key to Order. How do I create and associate these without | |
for producttype in campaign.product_types: | |
Product.objects.update_or_create( | |
order=self.instance, | |
product_type=producttype, | |
defaults=???) | |
return super().save(commit=commit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment