mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -1,8 +1,6 @@
|
||||
import uuid
|
||||
|
||||
from django.contrib.contenttypes.fields import (
|
||||
GenericForeignKey, GenericRelation,
|
||||
)
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import models
|
||||
from django.db.models.query import ModelIterable
|
||||
@@ -11,12 +9,15 @@ from django.utils.functional import cached_property
|
||||
|
||||
class Author(models.Model):
|
||||
name = models.CharField(max_length=50, unique=True)
|
||||
first_book = models.ForeignKey('Book', models.CASCADE, related_name='first_time_authors')
|
||||
first_book = models.ForeignKey(
|
||||
"Book", models.CASCADE, related_name="first_time_authors"
|
||||
)
|
||||
favorite_authors = models.ManyToManyField(
|
||||
'self', through='FavoriteAuthors', symmetrical=False, related_name='favors_me')
|
||||
"self", through="FavoriteAuthors", symmetrical=False, related_name="favors_me"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@@ -28,34 +29,39 @@ class AuthorWithAge(Author):
|
||||
|
||||
|
||||
class FavoriteAuthors(models.Model):
|
||||
author = models.ForeignKey(Author, models.CASCADE, to_field='name', related_name='i_like')
|
||||
likes_author = models.ForeignKey(Author, models.CASCADE, to_field='name', related_name='likes_me')
|
||||
author = models.ForeignKey(
|
||||
Author, models.CASCADE, to_field="name", related_name="i_like"
|
||||
)
|
||||
likes_author = models.ForeignKey(
|
||||
Author, models.CASCADE, to_field="name", related_name="likes_me"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
|
||||
class AuthorAddress(models.Model):
|
||||
author = models.ForeignKey(Author, models.CASCADE, to_field='name', related_name='addresses')
|
||||
author = models.ForeignKey(
|
||||
Author, models.CASCADE, to_field="name", related_name="addresses"
|
||||
)
|
||||
address = models.TextField()
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
|
||||
class Book(models.Model):
|
||||
title = models.CharField(max_length=255)
|
||||
authors = models.ManyToManyField(Author, related_name='books')
|
||||
authors = models.ManyToManyField(Author, related_name="books")
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
|
||||
class BookWithYear(Book):
|
||||
book = models.OneToOneField(Book, models.CASCADE, parent_link=True)
|
||||
published_year = models.IntegerField()
|
||||
aged_authors = models.ManyToManyField(
|
||||
AuthorWithAge, related_name='books_with_year')
|
||||
aged_authors = models.ManyToManyField(AuthorWithAge, related_name="books_with_year")
|
||||
|
||||
|
||||
class Bio(models.Model):
|
||||
@@ -63,17 +69,17 @@ class Bio(models.Model):
|
||||
Author,
|
||||
models.CASCADE,
|
||||
primary_key=True,
|
||||
to_field='name',
|
||||
to_field="name",
|
||||
)
|
||||
books = models.ManyToManyField(Book, blank=True)
|
||||
|
||||
|
||||
class Reader(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
books_read = models.ManyToManyField(Book, related_name='read_by')
|
||||
books_read = models.ManyToManyField(Book, related_name="read_by")
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@@ -87,11 +93,12 @@ class BookReview(models.Model):
|
||||
|
||||
# Models for default manager tests
|
||||
|
||||
|
||||
class Qualification(models.Model):
|
||||
name = models.CharField(max_length=10)
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
|
||||
class ModelIterableSubclass(ModelIterable):
|
||||
@@ -106,7 +113,7 @@ class TeacherQuerySet(models.QuerySet):
|
||||
|
||||
class TeacherManager(models.Manager):
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().prefetch_related('qualifications')
|
||||
return super().get_queryset().prefetch_related("qualifications")
|
||||
|
||||
|
||||
class Teacher(models.Model):
|
||||
@@ -117,10 +124,13 @@ class Teacher(models.Model):
|
||||
objects_custom = TeacherQuerySet.as_manager()
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
def __str__(self):
|
||||
return "%s (%s)" % (self.name, ", ".join(q.name for q in self.qualifications.all()))
|
||||
return "%s (%s)" % (
|
||||
self.name,
|
||||
", ".join(q.name for q in self.qualifications.all()),
|
||||
)
|
||||
|
||||
|
||||
class Department(models.Model):
|
||||
@@ -128,11 +138,12 @@ class Department(models.Model):
|
||||
teachers = models.ManyToManyField(Teacher)
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
|
||||
# GenericRelation/GenericForeignKey tests
|
||||
|
||||
|
||||
class TaggedItem(models.Model):
|
||||
tag = models.SlugField()
|
||||
content_type = models.ForeignKey(
|
||||
@@ -141,26 +152,29 @@ class TaggedItem(models.Model):
|
||||
related_name="taggeditem_set2",
|
||||
)
|
||||
object_id = models.PositiveIntegerField()
|
||||
content_object = GenericForeignKey('content_type', 'object_id')
|
||||
content_object = GenericForeignKey("content_type", "object_id")
|
||||
created_by_ct = models.ForeignKey(
|
||||
ContentType,
|
||||
models.SET_NULL,
|
||||
null=True,
|
||||
related_name='taggeditem_set3',
|
||||
related_name="taggeditem_set3",
|
||||
)
|
||||
created_by_fkey = models.PositiveIntegerField(null=True)
|
||||
created_by = GenericForeignKey('created_by_ct', 'created_by_fkey',)
|
||||
created_by = GenericForeignKey(
|
||||
"created_by_ct",
|
||||
"created_by_fkey",
|
||||
)
|
||||
favorite_ct = models.ForeignKey(
|
||||
ContentType,
|
||||
models.SET_NULL,
|
||||
null=True,
|
||||
related_name='taggeditem_set4',
|
||||
related_name="taggeditem_set4",
|
||||
)
|
||||
favorite_fkey = models.CharField(max_length=64, null=True)
|
||||
favorite = GenericForeignKey('favorite_ct', 'favorite_fkey')
|
||||
favorite = GenericForeignKey("favorite_ct", "favorite_fkey")
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
|
||||
class Article(models.Model):
|
||||
@@ -170,14 +184,16 @@ class Article(models.Model):
|
||||
|
||||
class Bookmark(models.Model):
|
||||
url = models.URLField()
|
||||
tags = GenericRelation(TaggedItem, related_query_name='bookmarks')
|
||||
favorite_tags = GenericRelation(TaggedItem,
|
||||
content_type_field='favorite_ct',
|
||||
object_id_field='favorite_fkey',
|
||||
related_query_name='favorite_bookmarks')
|
||||
tags = GenericRelation(TaggedItem, related_query_name="bookmarks")
|
||||
favorite_tags = GenericRelation(
|
||||
TaggedItem,
|
||||
content_type_field="favorite_ct",
|
||||
object_id_field="favorite_fkey",
|
||||
related_query_name="favorite_bookmarks",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
|
||||
class Comment(models.Model):
|
||||
@@ -187,37 +203,44 @@ class Comment(models.Model):
|
||||
content_type = models.ForeignKey(ContentType, models.CASCADE, null=True)
|
||||
object_pk = models.TextField()
|
||||
content_object = GenericForeignKey(ct_field="content_type", fk_field="object_pk")
|
||||
content_type_uuid = models.ForeignKey(ContentType, models.CASCADE, related_name='comments', null=True)
|
||||
content_type_uuid = models.ForeignKey(
|
||||
ContentType, models.CASCADE, related_name="comments", null=True
|
||||
)
|
||||
object_pk_uuid = models.TextField()
|
||||
content_object_uuid = GenericForeignKey(ct_field='content_type_uuid', fk_field='object_pk_uuid')
|
||||
content_object_uuid = GenericForeignKey(
|
||||
ct_field="content_type_uuid", fk_field="object_pk_uuid"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
|
||||
# Models for lookup ordering tests
|
||||
|
||||
|
||||
class House(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
address = models.CharField(max_length=255)
|
||||
owner = models.ForeignKey('Person', models.SET_NULL, null=True)
|
||||
main_room = models.OneToOneField('Room', models.SET_NULL, related_name='main_room_of', null=True)
|
||||
owner = models.ForeignKey("Person", models.SET_NULL, null=True)
|
||||
main_room = models.OneToOneField(
|
||||
"Room", models.SET_NULL, related_name="main_room_of", null=True
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
|
||||
class Room(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
house = models.ForeignKey(House, models.CASCADE, related_name='rooms')
|
||||
house = models.ForeignKey(House, models.CASCADE, related_name="rooms")
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
|
||||
class Person(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
houses = models.ManyToManyField(House, related_name='occupants')
|
||||
houses = models.ManyToManyField(House, related_name="occupants")
|
||||
|
||||
@property
|
||||
def primary_house(self):
|
||||
@@ -233,21 +256,23 @@ class Person(models.Model):
|
||||
return self.all_houses
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
|
||||
# Models for nullable FK tests
|
||||
|
||||
|
||||
class Employee(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
boss = models.ForeignKey('self', models.SET_NULL, null=True, related_name='serfs')
|
||||
boss = models.ForeignKey("self", models.SET_NULL, null=True, related_name="serfs")
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
|
||||
# Ticket #19607
|
||||
|
||||
|
||||
class LessonEntry(models.Model):
|
||||
name1 = models.CharField(max_length=200)
|
||||
name2 = models.CharField(max_length=200)
|
||||
@@ -260,25 +285,31 @@ class WordEntry(models.Model):
|
||||
|
||||
# Ticket #21410: Regression when related_name="+"
|
||||
|
||||
|
||||
class Author2(models.Model):
|
||||
name = models.CharField(max_length=50, unique=True)
|
||||
first_book = models.ForeignKey('Book', models.CASCADE, related_name='first_time_authors+')
|
||||
favorite_books = models.ManyToManyField('Book', related_name='+')
|
||||
first_book = models.ForeignKey(
|
||||
"Book", models.CASCADE, related_name="first_time_authors+"
|
||||
)
|
||||
favorite_books = models.ManyToManyField("Book", related_name="+")
|
||||
|
||||
class Meta:
|
||||
ordering = ['id']
|
||||
ordering = ["id"]
|
||||
|
||||
|
||||
# Models for many-to-many with UUID pk test:
|
||||
|
||||
|
||||
class Pet(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
name = models.CharField(max_length=20)
|
||||
people = models.ManyToManyField(Person, related_name='pets')
|
||||
people = models.ManyToManyField(Person, related_name="pets")
|
||||
|
||||
|
||||
class Flea(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
current_room = models.ForeignKey(Room, models.SET_NULL, related_name='fleas', null=True)
|
||||
pets_visited = models.ManyToManyField(Pet, related_name='fleas_hosted')
|
||||
people_visited = models.ManyToManyField(Person, related_name='fleas_hosted')
|
||||
current_room = models.ForeignKey(
|
||||
Room, models.SET_NULL, related_name="fleas", null=True
|
||||
)
|
||||
pets_visited = models.ManyToManyField(Pet, related_name="fleas_hosted")
|
||||
people_visited = models.ManyToManyField(Person, related_name="fleas_hosted")
|
||||
|
||||
Reference in New Issue
Block a user