I am writing a Django program where Department/Position fields are associated with the User model. On the registration page, a person is required to enter first/last name, email, username, password, which are default User model fields, as well as their department and position.
And then below are the two models I created.
class Department(models.Model):
department_id = models.AutoField(primary_key=True)
department_name = models.CharField(max_length=100, unique=True)
is_active = models.BooleanField(default=True)
class Position(models.Model):
position_id = models.AutoField(primary_key=True)
position_name = models.CharField(max_length=100)
department = models.ForeignKey(Department)
user = models.OneToOneField(User, blank=True, related_name="position")
In views.py, the associated view goes like this:
def sign_up_in(request):
global user
post = request.POST
if post['email'] is u'' or post['password'] is u'':
msg = 'Please check sign-up input forms'
return render_to_response('none.html', {'msg': msg})
else:
if not user_exists(post['email']):
user = create_user(username=post['email'], email=post['email'], password=post['password'])
user.first_name=post['first']
user.last_name=post['last']
**user.position.position_name=post['position']**
user.department=post['department']
user.is_staff = True
user.save()
msg = 'Sign Up OK ' + user.first_name + ' ' + user.last_name
else:
msg = 'Existing User'
return render_to_response('login.html', {'msg': msg})
When I added the boldfaced line in views.py above, I started getting the error "No exception supplied". What should I change in the models, and views? Also, in this line of code, user = create_user(username=post['email'], email=post['email'], password=post['password']), how should I express the foreign key relation?