Code

Ticket #2145: djt-2145-one_to_one_field-contribution.diff

File djt-2145-one_to_one_field-contribution.diff, 958 bytes (added by Jeremy Dunck <jdunck@…>, 7 years ago)

Contribute to restaurant, not place.

Line 
1Index: django/db/models/fields/related.py
2===================================================================
3--- django/db/models/fields/related.py  (revision 5194)
4+++ django/db/models/fields/related.py  (working copy)
5@@ -613,11 +613,13 @@
6         super(OneToOneField, self).contribute_to_class(cls, name)
7         setattr(cls, self.name, ReverseSingleRelatedObjectDescriptor(self))
8 
9-    def contribute_to_related_class(self, cls, related):
10-        setattr(cls, related.get_accessor_name(), SingleRelatedObjectDescriptor(related))
11         if not cls._meta.one_to_one_field:
12             cls._meta.one_to_one_field = self
13 
14+    def contribute_to_related_class(self, cls, related):
15+        setattr(cls, related.get_accessor_name(), SingleRelatedObjectDescriptor(related))
16+
17+
18     def formfield(self, **kwargs):
19         defaults = {'form_class': forms.ModelChoiceField, 'queryset': self.rel.to._default_manager.all()}
20         defaults.update(kwargs)