Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. from django.contrib.auth.models import User
  2. from django.db import models
  3.  
  4. class Profile(models.Model):
  5. user = models.OneToOneField(User)
  6. display_name = models.CharField(max_length=145, blank=True, null=True)
  7. bio = models.CharField(max_length=1000, blank=True, null=True)
  8.  
  9. class Module(models.Model):
  10. name = models.CharField(max_length=45)
  11. semester = models.CharField(max_length=40)
  12. prof = models.ForeignKey('Profile', null=True, blank=True)
  13.  
  14. class ModuleForm(ModelForm):
  15. class Meta:
  16. model = Module
  17. fields = ['name', 'semester']
  18.  
  19. prof = Profile.objects.get(user=request.user)
  20. if request.method == 'POST':
  21. mtb = request.POST._mutable
  22. request.POST._mutable = True
  23. request.POST['prof'] = str(prof.id)
  24. request.POST._mutable = mtb
  25. moduleform = ModuleForm(request.POST)
  26. moduleform.save()
  27.  
  28. moduleform.save(commit=False)
  29. moduleform.prof = prof
  30. moduleform.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement