Trying to create a generic FK using ContentType. In admin, the menu lists all the models. Since I only ever need to select 1 of 2 different models, anyway to limit the choice?
Setting the choices attribute as Django complains must be a "ContentType" instance ContentType.objects.get() returns an instance of a particular model, not ContentType (as one would expect), so I'm not sure how to create an instance with the particulars I need to point to something specific in the choices list. Here's what I have: from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic class GenericFKExample(models.Model): CHOICES = ( (ContentType.objects.get(model="model1"), "Model 1"), (ContentType.objects.get(model="model2"), "Model 2"), ) content_type = models.ForeignKey(ContentType, choices = CHOICES, null = True, ) object_id = models.PositiveIntegerField( null = True, ) content_object = generic.GenericForeignKey( "content_type", "object_id" ) Obviously, if I don't use choices, it works but then I have a very long list of model choices. -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---