You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> Foo.objects.create(foo='some foo text')
ValueError: Cannot assign "'some foo text'": "Foo.foo" must be a "Foo" instance.
In fact, if model Bar is a subclass of Base and has a foo field/method/property, we have the same problem, because the foo attribute for every subclass of Base is trying to reference a Foo instance.
i'm not sure what the internal use of that property is, but how about we allow the name of the property to be overridden (via a method on the base class which could be overridden), or perhaps auto-generate a name like _foo instead? Otherwise, this means that no field on any child model can match the name of its own class or of a class having the same base.
The text was updated successfully, but these errors were encountered:
To have model inheritance, Django adds an implicit base_ptr = OneToOneField(Base, related_name='foo', primary_key=True, parent_link=True) field to Foo that acts as primary key to the Base model. When you explicitly define the key, you might be able to change the related_name so they don't clash with your properties.
Let's say we have the following models:
We can't set
Foo.foo
becauseFoo.foo
is overwritten as an attribute referencing itself... (i believe that is happening here):In fact, if model
Bar
is a subclass ofBase
and has afoo
field/method/property, we have the same problem, because thefoo
attribute for every subclass ofBase
is trying to reference aFoo
instance.i'm not sure what the internal use of that property is, but how about we allow the name of the property to be overridden (via a method on the base class which could be overridden), or perhaps auto-generate a name like
_foo
instead? Otherwise, this means that no field on any child model can match the name of its own class or of a class having the same base.The text was updated successfully, but these errors were encountered: