Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.contrib.auth.models import User
- from django.db import models
- class Profile(models.Model):
- user = models.OneToOneField(User)
- display_name = models.CharField(max_length=145, blank=True, null=True)
- bio = models.CharField(max_length=1000, blank=True, null=True)
- class Module(models.Model):
- name = models.CharField(max_length=45)
- semester = models.CharField(max_length=40)
- prof = models.ForeignKey('Profile', null=True, blank=True)
- class ModuleForm(ModelForm):
- class Meta:
- model = Module
- fields = ['name', 'semester']
- prof = Profile.objects.get(user=request.user)
- if request.method == 'POST':
- mtb = request.POST._mutable
- request.POST._mutable = True
- request.POST['prof'] = str(prof.id)
- request.POST._mutable = mtb
- moduleform = ModuleForm(request.POST)
- moduleform.save()
- moduleform.save(commit=False)
- moduleform.prof = prof
- moduleform.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement