﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15054	ContentTypes and proxied models	jakedrake	nobody	"An interesting and useful usage of proxy models and ContentTypes is for implementing the [http://en.wikipedia.org/wiki/Template_method_pattern Template Method] design pattern. This is a design pattern that others ([http://groups.google.com/group/django-users/browse_thread/thread/70eb4e38309cf839/41b20a8e061fc927?show_docid=41b20a8e061fc927 1] and [http://groups.google.com/group/django-users/browse_thread/thread/06475f3a93c0f782/eaa87f736b0ee164?show_docid=eaa87f736b0ee164 2]) have discussed as well.

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 [http://code.djangoproject.com/changeset/10523 #10523] for ticket [http://code.djangoproject.com/ticket/10738 #10738]. This change appears to affect at least one [http://code.djangoproject.com/ticket/11154 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.

regards,

JD"		closed	Contrib apps	1.2		duplicate	contentype proxy		Unreviewed	0	0	0	0	0	0
