O'Reilly logo

Django Unleashed by Andrew Pinkham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

22.5 Adding an Author to Blog Posts

Given that we are allowing specific users to write blog posts, it would be nice if we identified which blog post was written by which user. We can connect our Post to the User model exactly as if we had never customized it, as shown in Example 22.54.

Example 22.54: Project Code

blog/models.py in 9515ba8ede

 1   from django.conf import settings  .       ... 12   class Post(models.Model):  .       ... 18       author = models.ForeignKey( 19           settings.AUTH_USER_MODEL, 20           related_name='blog_posts')

Hopefully, our dependency on the use of get_user_model() and relations built using the setting.AUTH_USER_MODEL is a lot clearer than before. We won’t always know which ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required