22.2.1 The Profile Model

The 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

user/models.py in 23e819627f

 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, ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.