ContentTypes and proxied models
|Reported by:||jakedrake||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
As an example of a template method, a base template model is created, which has its own table, and proxy subclasses implement different behavior, and are stored in the base template table. This is used for abstracting actions on the contents of a model:
class RelationshipAction( Model ): content_type = models.ForeignKey(ContentType,editable=False,null=True) userA = ForeignKey('User') userB = ForeignKey('User') def do_something(self, *args, **kwargs): pass class CreateFriendship( RelationshipAction ): userA = ForeignKey('User') userB = ForeignKey('User') class Meta: proxy = True def do_something(self, *args, **kwargs): userA.relationships.add(userB) super(CreateFriendship, self).do_something(*args, **kwargs)
However, the base class in this case, RelationshipAction, gets saved as the ContentType instead of CreateFriendship. This is due to the fix committed in changeset #10523 for ticket #10738. This change appears to affect at least one other ticket.
Not having worked in Django source code development for very long, the repercussions and perils of re-enabling this behavior (by reverting changeset #10523) are not clear to me. If this is not a suitable solution, would it be useful to have an addition flag in the Meta class which enables subclass ContentTypes for proxied classes?
thank you in advance.