November 2015
Beginner to intermediate
840 pages
26h 30m
English
Profile ModelThe Profile model itself is nothing fancy or interesting, with the exception of the relation to User, as shown in Example 22.1.
Example 22.1: Project Code
1 from django.conf import settings 2 from django.db import models 3 4 5 class Profile(models.Model): 6 user = models.OneToOneField( 7 settings.AUTH_USER_MODEL) 8 slug = models.SlugField( 9 max_length=30, 10 unique=True) 11 about = models.TextField() 12 13 def --str--(self): 14 return self.user.get_username()
The one-to-one relation to the user is created by the OneToOneField. When building code in other sections of the website, ...
Read now
Unlock full access