Skip to content

Instantly share code, notes, and snippets.

@sleekslush
Forked from dnoyes/gist:1674741
Created January 25, 2012 14:53
Show Gist options
  • Save sleekslush/1676619 to your computer and use it in GitHub Desktop.
Save sleekslush/1676619 to your computer and use it in GitHub Desktop.
creating a team (django)
# teams/views.py
@login_required()
def create(request):
form = CreateTeamForm(request.POST or None, request.FILES or None)
if form.is_valid():
team = form.save(commit=False)
team.status = STATUS.ACTIVE
team.creator = request.user
team.save()
form.save_m2m()
return HttpResponseRedirect('/teams/' + team.slug)
return render(request, 'teams/team_form.html', {'form': form})
@dnoyes
Copy link

dnoyes commented Jan 25, 2012

I'm leaning towards liking it.

@sleekslush
Copy link
Author

It's a pretty common django paradigm. I only use it if I have similar code to yours. Where on a GET, it's just a form create. On a POST, I process the form. If I'm doing anything else that requires more than that in the 2 conditions, I'll expand it out and be explicit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment