Skip to content

Commit 3f53aa9

Browse files
committed
Use lazy evaluated ForeignKey references to prevent future problems
Starting with Django 1.7 there have been multiple people hitting #django with problems that eventually could be solved using lazy references to related models instead of class references. Teaching it this ways seems to be a good way to prevent future issues.
1 parent 243f5a0 commit 3f53aa9

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

django_models/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,9 @@ Let's open `blog/models.py`, remove everything from it and write code like this:
101101

102102
from django.db import models
103103
from django.utils import timezone
104-
from django.contrib.auth.models import User
105104

106105
class Post(models.Model):
107-
author = models.ForeignKey(User)
106+
author = models.ForeignKey('auth.User')
108107
title = models.CharField(max_length=200)
109108
text = models.TextField()
110109
created_date = models.DateTimeField(

0 commit comments

Comments
 (0)