I've got two models. Here's what I'm trying to do:

class InterestSet(models.Model, MailChimpAPIMixin):
    name = models.CharField(help_text="The interest grouping to add.
Grouping names must be unique.", max_length=128, unique=True)
    content_type = models.ForeignKey(ContentType, blank=True,
null=True)

class InterestGroup(models.Model, MailChimpAPIMixin):
    name = models.CharField(max_length=128, unique=True)
    interest_grouping = models.ForeignKey(InterestGrouping)
    object_id = models.PositiveIntegerField(blank=True, null=True)
    content_object =
generic.GenericForeignKey('interest_set__content_type', 'object_id')


Basically, I want to define a content type for an Interest Set on the
"parent" model. Then, for each Interest Group, I want the object id to
always refer to the content type set on Interest Set. You can see by
the first argument to GenericForeignKey() how I wish it worked.

Alas it does not. Plan B is just to move the content_type field back
to Interest Grouping and deal (or possibly just custom code my
relationships without relying on GenericForeignKey). It's a shame
because it duplicates data unnecessarily and creates an opportunity
for a relationship to be created that violates a business rule for
this application (which is that all Interest Groups in an Interest Set
must be related to the same content type).

I'm just wondering if either a) I'm missing an obvious way to
accomplish this or b) this has come up before or been discussed
somewhere. I might explore the possibility of patching the source code
to enable this behavior of that sounds at all desirable.

Let me know your thoughts. Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to