Last active
March 12, 2026 14:13
-
-
Save neara/6209563 to your computer and use it in GitHub Desktop.
Revisions
-
neara revised this gist
Aug 19, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ from forms import SponsorForm, SponsorShipsFormSet class CreateSponsor(CreateView): form_class = SponsorForm template_name = 'sponsor_form.html' -
neara revised this gist
Aug 18, 2013 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -23,9 +23,9 @@ def form_valid(self, form): form.instance.created_by = self.request.user form.instance.updated_by = self.request.user self.object = form.save() if sponsorships.is_valid(): sponsorships.instance = self.object sponsorships.save() return super(CreateSponsor, self).form_valid(form) -
neara created this gist
Aug 12, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ from django.forms import ModelForm from django.forms.models import inlineformset_factory from models import Sponsor, Sponsorship class SponsorForm(ModelForm): class Meta: model = Sponsor class SponsorshipForm(ModelForm): class Meta: model = Sponsorship SponsorShipsFormSet = inlineformset_factory(Sponsor, Sponsorship, form=SponsorshipForm, extra=2) 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ from django.db import transaction from django.views.generic import CreateView from forms import SponsorForm, SponsorShipsFormSet class CreateSponsor(SponsorMixin, CreateView): form_class = SponsorForm template_name = 'sponsor_form.html' def get_context_data(self, **kwargs): data = super(CreateSponsor, self).get_context_data(**kwargs) if self.request.POST: data['sponsorships'] = SponsorShipsFormSet(self.request.POST) else: data['sponsorships'] = SponsorShipsFormSet() return data def form_valid(self, form): context = self.get_context_data() sponsorships = context['sponsorships'] with transaction.commit_on_success(): form.instance.created_by = self.request.user form.instance.updated_by = self.request.user self.object = form.save() sponsorships.instance = self.object sponsorships.save() return super(CreateSponsor, self).form_valid(form) def get_success_url(self): return reverse('sponsors')