mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -9,9 +9,7 @@ There are two reasons you might want to customize a ``Manager``: to add extra
|
||||
returns.
|
||||
"""
|
||||
|
||||
from django.contrib.contenttypes.fields import (
|
||||
GenericForeignKey, GenericRelation,
|
||||
)
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
||||
from django.db import models
|
||||
|
||||
|
||||
@@ -27,8 +25,10 @@ class PublishedBookManager(models.Manager):
|
||||
|
||||
class AnnotatedBookManager(models.Manager):
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().annotate(
|
||||
favorite_avg=models.Avg('favorite_books__favorite_thing_id')
|
||||
return (
|
||||
super()
|
||||
.get_queryset()
|
||||
.annotate(favorite_avg=models.Avg("favorite_books__favorite_thing_id"))
|
||||
)
|
||||
|
||||
|
||||
@@ -46,10 +46,12 @@ class CustomQuerySet(models.QuerySet):
|
||||
|
||||
def optout_public_method(self, *args, **kwargs):
|
||||
return self.all()
|
||||
|
||||
optout_public_method.queryset_only = True
|
||||
|
||||
def _optin_private_method(self, *args, **kwargs):
|
||||
return self.all()
|
||||
|
||||
_optin_private_method.queryset_only = False
|
||||
|
||||
|
||||
@@ -72,12 +74,13 @@ CustomManager = BaseCustomManager.from_queryset(CustomQuerySet)
|
||||
|
||||
class CustomInitQuerySet(models.QuerySet):
|
||||
# QuerySet with an __init__() method that takes an additional argument.
|
||||
def __init__(self, custom_optional_arg=None, model=None, query=None, using=None, hints=None):
|
||||
def __init__(
|
||||
self, custom_optional_arg=None, model=None, query=None, using=None, hints=None
|
||||
):
|
||||
super().__init__(model=model, query=query, using=using, hints=hints)
|
||||
|
||||
|
||||
class DeconstructibleCustomManager(BaseCustomManager.from_queryset(CustomQuerySet)):
|
||||
|
||||
def __init__(self, a, b, c=1, d=2):
|
||||
super().__init__(a)
|
||||
|
||||
@@ -97,17 +100,21 @@ class Person(models.Model):
|
||||
last_name = models.CharField(max_length=30)
|
||||
fun = models.BooleanField(default=False)
|
||||
|
||||
favorite_book = models.ForeignKey('Book', models.SET_NULL, null=True, related_name='favorite_books')
|
||||
favorite_thing_type = models.ForeignKey('contenttypes.ContentType', models.SET_NULL, null=True)
|
||||
favorite_book = models.ForeignKey(
|
||||
"Book", models.SET_NULL, null=True, related_name="favorite_books"
|
||||
)
|
||||
favorite_thing_type = models.ForeignKey(
|
||||
"contenttypes.ContentType", models.SET_NULL, null=True
|
||||
)
|
||||
favorite_thing_id = models.IntegerField(null=True)
|
||||
favorite_thing = GenericForeignKey('favorite_thing_type', 'favorite_thing_id')
|
||||
favorite_thing = GenericForeignKey("favorite_thing_type", "favorite_thing_id")
|
||||
|
||||
objects = PersonManager()
|
||||
fun_people = FunPeopleManager()
|
||||
boring_people = BoringPeopleManager()
|
||||
|
||||
custom_queryset_default_manager = CustomQuerySet.as_manager()
|
||||
custom_queryset_custom_manager = CustomManager('hello')
|
||||
custom_queryset_custom_manager = CustomManager("hello")
|
||||
custom_init_queryset_manager = CustomInitQuerySet.as_manager()
|
||||
|
||||
def __str__(self):
|
||||
@@ -119,14 +126,16 @@ class FunPerson(models.Model):
|
||||
last_name = models.CharField(max_length=30)
|
||||
fun = models.BooleanField(default=True)
|
||||
favorite_book = models.ForeignKey(
|
||||
'Book',
|
||||
"Book",
|
||||
models.SET_NULL,
|
||||
null=True,
|
||||
related_name='fun_people_favorite_books',
|
||||
related_name="fun_people_favorite_books",
|
||||
)
|
||||
favorite_thing_type = models.ForeignKey(
|
||||
"contenttypes.ContentType", models.SET_NULL, null=True
|
||||
)
|
||||
favorite_thing_type = models.ForeignKey('contenttypes.ContentType', models.SET_NULL, null=True)
|
||||
favorite_thing_id = models.IntegerField(null=True)
|
||||
favorite_thing = GenericForeignKey('favorite_thing_type', 'favorite_thing_id')
|
||||
favorite_thing = GenericForeignKey("favorite_thing_type", "favorite_thing_id")
|
||||
|
||||
objects = FunPeopleManager()
|
||||
|
||||
@@ -135,24 +144,24 @@ class Book(models.Model):
|
||||
title = models.CharField(max_length=50)
|
||||
author = models.CharField(max_length=30)
|
||||
is_published = models.BooleanField(default=False)
|
||||
authors = models.ManyToManyField(Person, related_name='books')
|
||||
fun_authors = models.ManyToManyField(FunPerson, related_name='books')
|
||||
authors = models.ManyToManyField(Person, related_name="books")
|
||||
fun_authors = models.ManyToManyField(FunPerson, related_name="books")
|
||||
favorite_things = GenericRelation(
|
||||
Person,
|
||||
content_type_field='favorite_thing_type',
|
||||
object_id_field='favorite_thing_id',
|
||||
content_type_field="favorite_thing_type",
|
||||
object_id_field="favorite_thing_id",
|
||||
)
|
||||
fun_people_favorite_things = GenericRelation(
|
||||
FunPerson,
|
||||
content_type_field='favorite_thing_type',
|
||||
object_id_field='favorite_thing_id',
|
||||
content_type_field="favorite_thing_type",
|
||||
object_id_field="favorite_thing_id",
|
||||
)
|
||||
|
||||
published_objects = PublishedBookManager()
|
||||
annotated_objects = AnnotatedBookManager()
|
||||
|
||||
class Meta:
|
||||
base_manager_name = 'annotated_objects'
|
||||
base_manager_name = "annotated_objects"
|
||||
|
||||
|
||||
class ConfusedBook(models.Model):
|
||||
@@ -160,14 +169,14 @@ class ConfusedBook(models.Model):
|
||||
author = models.CharField(max_length=30)
|
||||
favorite_things = GenericRelation(
|
||||
Person,
|
||||
content_type_field='favorite_thing_type',
|
||||
object_id_field='favorite_thing_id',
|
||||
content_type_field="favorite_thing_type",
|
||||
object_id_field="favorite_thing_id",
|
||||
)
|
||||
less_favorite_things = GenericRelation(
|
||||
FunPerson,
|
||||
content_type_field='favorite_thing_type',
|
||||
object_id_field='favorite_thing_id',
|
||||
related_query_name='favorite_things',
|
||||
content_type_field="favorite_thing_type",
|
||||
object_id_field="favorite_thing_id",
|
||||
related_query_name="favorite_things",
|
||||
)
|
||||
|
||||
|
||||
@@ -187,13 +196,13 @@ class Car(models.Model):
|
||||
class FastCarAsBase(Car):
|
||||
class Meta:
|
||||
proxy = True
|
||||
base_manager_name = 'fast_cars'
|
||||
base_manager_name = "fast_cars"
|
||||
|
||||
|
||||
class FastCarAsDefault(Car):
|
||||
class Meta:
|
||||
proxy = True
|
||||
default_manager_name = 'fast_cars'
|
||||
default_manager_name = "fast_cars"
|
||||
|
||||
|
||||
class RestrictedManager(models.Manager):
|
||||
|
||||
Reference in New Issue
Block a user