Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Code:
Selected Language:
Show Linenumbers:
Short link for Twitter:
HTML:

HTML view:

Copy Source | Copy HTML
  1. #in forms.py
  2. class UserForm(forms.ModelForm):
  3.     class Meta:
  4.         model = User
  5.         fields = ["username", "email"]
  6.  
  7. class UserProfileForm(forms.ModelForm):
  8.     class Meta:
  9.         model = UserProfile
  10.  
  11. #in views.py
  12. def add_user(request):
  13.     ...
  14.     if request.method == "POST":
  15.         uform = UserForm(data = request.POST)
  16.         pform = UserProfileForm(data = request.POST)
  17.         if uform.is_valid() and pform.is_valid():
  18.             user = uform.save()
  19.             profile = pform.save(commit = False)
  20.             profile.user = user
  21.             profile.save()
  22.             ....
  23.     ...
  24.  
  25. #in template
  26. <form method="post">
  27.     {{ uform.as_p }}
  28.     {{ pform.as_p }}
  29.     <input type="submit" ...>
  30. </form>




Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2012