Fixed #23725 -- Substituted AUTH_USER_MODEL for User in docs.
This commit is contained in:
parent
cbd936d0f8
commit
68d3db8a7b
|
@ -1254,14 +1254,16 @@ The possible values for :attr:`~ForeignKey.on_delete` are found in
|
||||||
necessary to avoid executing queries at the time your models.py is
|
necessary to avoid executing queries at the time your models.py is
|
||||||
imported::
|
imported::
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
|
||||||
|
|
||||||
def get_sentinel_user():
|
def get_sentinel_user():
|
||||||
return User.objects.get_or_create(username='deleted')[0]
|
return get_user_model().objects.get_or_create(username='deleted')[0]
|
||||||
|
|
||||||
class MyModel(models.Model):
|
class MyModel(models.Model):
|
||||||
user = models.ForeignKey(User, on_delete=models.SET(get_sentinel_user))
|
user = models.ForeignKey(settings.AUTH_USER_MODEL,
|
||||||
|
on_delete=models.SET(get_sentinel_user))
|
||||||
|
|
||||||
* .. attribute:: DO_NOTHING
|
* .. attribute:: DO_NOTHING
|
||||||
|
|
||||||
|
@ -1515,12 +1517,12 @@ as default value.
|
||||||
|
|
||||||
With the following example::
|
With the following example::
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
|
||||||
|
|
||||||
class MySpecialUser(models.Model):
|
class MySpecialUser(models.Model):
|
||||||
user = models.OneToOneField(User)
|
user = models.OneToOneField(settings.AUTH_USER_MODEL)
|
||||||
supervisor = models.OneToOneField(User, related_name='supervisor_of')
|
supervisor = models.OneToOneField(settings.AUTH_USER_MODEL, related_name='supervisor_of')
|
||||||
|
|
||||||
your resulting ``User`` model will have the following attributes::
|
your resulting ``User`` model will have the following attributes::
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue