Warn (or solve) if there are duplicate child class field names
KrzysiekJ opened this issue · 2 comments
This issue is a copy of KrzysiekJ#1 by @mnieber.
The following does not work because the name "request_message" is duplicated in two child classes of the base class Message, which produces a conflict later on when querying the database.
class Message(TypedModel):
pass
class AcceptMessage(Message):
request_message = models.ForeignKey('self', null=True, blank=True, related_name='+')
class DeclineMessage(Message):
request_message = models.ForeignKey('self', null=True, blank=True, related_name='+')
This can be solved by moving request_message to the base class but this is not always what you want (perhaps a third class inheriting from Message does not have a request_message field).
It would be nice if TypedModel would at least raise an exception in this case so that the programmer becomes aware of the problem.
Perhaps it should work if the fields are exactly the same, but I don't know how we can reliably verify that... (f1.__dict__ == f2.__dict__
?)
Otherwise this should definitely throw an error.
Long time no speak, but since 2013 django's grown a reliable field serialisation and comparison scheme (for migrations) so this should be perfectly doable now.
If we find two fields exactly the same we can amalgamate them, and if they're different in any way but have the same name we can throw an error.