mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Refs #33476 -- Reformatted code with Black.
This commit is contained in:
committed by
Mariusz Felisiak
parent
f68fa8b45d
commit
9c19aff7c7
@@ -9,6 +9,7 @@ class CustomForeignObjectRel(models.ForeignObjectRel):
|
||||
Define some extra Field methods so this Rel acts more like a Field, which
|
||||
lets us use ReverseManyToOneDescriptor in both directions.
|
||||
"""
|
||||
|
||||
@property
|
||||
def foreign_related_fields(self):
|
||||
return tuple(lhs_field for lhs_field, rhs_field in self.field.related_fields)
|
||||
@@ -23,6 +24,7 @@ class StartsWithRelation(models.ForeignObject):
|
||||
the default equality operator. This is logically a many-to-many relation
|
||||
and creates a ReverseManyToOneDescriptor in both directions.
|
||||
"""
|
||||
|
||||
auto_created = False
|
||||
|
||||
many_to_many = False
|
||||
@@ -33,7 +35,7 @@ class StartsWithRelation(models.ForeignObject):
|
||||
rel_class = CustomForeignObjectRel
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['on_delete'] = models.DO_NOTHING
|
||||
kwargs["on_delete"] = models.DO_NOTHING
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@property
|
||||
@@ -54,28 +56,32 @@ class StartsWithRelation(models.ForeignObject):
|
||||
def get_path_info(self, filtered_relation=None):
|
||||
to_opts = self.remote_field.model._meta
|
||||
from_opts = self.model._meta
|
||||
return [PathInfo(
|
||||
from_opts=from_opts,
|
||||
to_opts=to_opts,
|
||||
target_fields=(to_opts.pk,),
|
||||
join_field=self,
|
||||
m2m=False,
|
||||
direct=False,
|
||||
filtered_relation=filtered_relation,
|
||||
)]
|
||||
return [
|
||||
PathInfo(
|
||||
from_opts=from_opts,
|
||||
to_opts=to_opts,
|
||||
target_fields=(to_opts.pk,),
|
||||
join_field=self,
|
||||
m2m=False,
|
||||
direct=False,
|
||||
filtered_relation=filtered_relation,
|
||||
)
|
||||
]
|
||||
|
||||
def get_reverse_path_info(self, filtered_relation=None):
|
||||
to_opts = self.model._meta
|
||||
from_opts = self.remote_field.model._meta
|
||||
return [PathInfo(
|
||||
from_opts=from_opts,
|
||||
to_opts=to_opts,
|
||||
target_fields=(to_opts.pk,),
|
||||
join_field=self.remote_field,
|
||||
m2m=False,
|
||||
direct=False,
|
||||
filtered_relation=filtered_relation,
|
||||
)]
|
||||
return [
|
||||
PathInfo(
|
||||
from_opts=from_opts,
|
||||
to_opts=to_opts,
|
||||
target_fields=(to_opts.pk,),
|
||||
join_field=self.remote_field,
|
||||
m2m=False,
|
||||
direct=False,
|
||||
filtered_relation=filtered_relation,
|
||||
)
|
||||
]
|
||||
|
||||
def contribute_to_class(self, cls, name, private_only=False):
|
||||
super().contribute_to_class(cls, name, private_only)
|
||||
@@ -87,6 +93,7 @@ class BrokenContainsRelation(StartsWithRelation):
|
||||
This model is designed to yield no join conditions and
|
||||
raise an exception in ``Join.as_sql()``.
|
||||
"""
|
||||
|
||||
def get_extra_restriction(self, alias, related_alias):
|
||||
return None
|
||||
|
||||
@@ -94,19 +101,19 @@ class BrokenContainsRelation(StartsWithRelation):
|
||||
class SlugPage(models.Model):
|
||||
slug = models.CharField(max_length=20, unique=True)
|
||||
descendants = StartsWithRelation(
|
||||
'self',
|
||||
from_fields=['slug'],
|
||||
to_fields=['slug'],
|
||||
related_name='ascendants',
|
||||
"self",
|
||||
from_fields=["slug"],
|
||||
to_fields=["slug"],
|
||||
related_name="ascendants",
|
||||
)
|
||||
containers = BrokenContainsRelation(
|
||||
'self',
|
||||
from_fields=['slug'],
|
||||
to_fields=['slug'],
|
||||
"self",
|
||||
from_fields=["slug"],
|
||||
to_fields=["slug"],
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ['slug']
|
||||
ordering = ["slug"]
|
||||
|
||||
def __str__(self):
|
||||
return 'SlugPage %s' % self.slug
|
||||
return "SlugPage %s" % self.slug
|
||||
|
||||
Reference in New Issue
Block a user