mirror of
https://github.com/django/django.git
synced 2025-10-30 17:16:10 +00:00
Fixed #21216 -- Allow OneToOneField reverse accessor to be hidden.
This commit is contained in:
@@ -960,6 +960,7 @@ class ManyToManyRel(object):
|
||||
class ForeignObject(RelatedField):
|
||||
requires_unique_target = True
|
||||
generate_reverse_relation = True
|
||||
related_accessor_class = ForeignRelatedObjectsDescriptor
|
||||
|
||||
def __init__(self, to, from_fields, to_fields, **kwargs):
|
||||
self.from_fields = from_fields
|
||||
@@ -1160,7 +1161,7 @@ class ForeignObject(RelatedField):
|
||||
# Internal FK's - i.e., those with a related name ending with '+' -
|
||||
# and swapped models don't get a related descriptor.
|
||||
if not self.rel.is_hidden() and not related.model._meta.swapped:
|
||||
setattr(cls, related.get_accessor_name(), ForeignRelatedObjectsDescriptor(related))
|
||||
setattr(cls, related.get_accessor_name(), self.related_accessor_class(related))
|
||||
if self.rel.limit_choices_to:
|
||||
cls._meta.related_fkey_lookups.append(self.rel.limit_choices_to)
|
||||
|
||||
@@ -1334,6 +1335,7 @@ class OneToOneField(ForeignKey):
|
||||
always returns the object pointed to (since there will only ever be one),
|
||||
rather than returning a list.
|
||||
"""
|
||||
related_accessor_class = SingleRelatedObjectDescriptor
|
||||
description = _("One-to-one relationship")
|
||||
|
||||
def __init__(self, to, to_field=None, **kwargs):
|
||||
@@ -1346,10 +1348,6 @@ class OneToOneField(ForeignKey):
|
||||
del kwargs['unique']
|
||||
return name, path, args, kwargs
|
||||
|
||||
def contribute_to_related_class(self, cls, related):
|
||||
setattr(cls, related.get_accessor_name(),
|
||||
SingleRelatedObjectDescriptor(related))
|
||||
|
||||
def formfield(self, **kwargs):
|
||||
if self.rel.parent_link:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user