I have read this and I have one question. How to take access to the ‘other fields’?
models:
class UsersProfile(models.Model):
def __unicode__(self):
return self.user.last_name
user = models.OneToOneField(User)
car_num = models.IntegerField('car ID')
captain = models.BooleanField()
views:
@login_required
def profile(request):
return render(request, 'profile.html')
So, after authentication, in profile works only user.last_login + etc, but not user.car_num or user.captain. I read about get_profile(), but where I need it to write?
profile = request.user.get_profile()
If it in views, how to return?
You can define a
related_namefor yourOneToOneField, like this:and then access the corresponding fields using