-
-
Save sleekslush/1676619 to your computer and use it in GitHub Desktop.
creating a team (django)
This file contains 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
# 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}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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