On Mon, 2008-09-15 at 18:10 -0700, Peter Bailey wrote: > Hi all. I have a set of classes (web page items like radios, > checkboxes, etc.) They are built on a superclass - Item. I need a > join table to link them to specific pages in which I also store a > position (PageItem) . Here is a snippet: > > # > ---------------------------------------------------------------------------------- > # will use this for subclassing into our item subtypes > # > ---------------------------------------------------------------------------------- > > class Item(models.Model): > name = models.CharField(max_length=30) > > def __unicode__(self): > return self.name > > class Meta: > abstract = True > > # > ---------------------------------------------------------------------------------- > > class Page(models.Model): > website = models.ForeignKey(Website) > position = models.IntegerField() > file_name = models.CharField(max_length=50) > h1_title = models.CharField(max_length=50) > > def __unicode__(self): > return self.file_name > > class Meta: > ordering = ["file_name"] > > # > ---------------------------------------------------------------------------------- > > class PageItem(models.Model): > page = models.ForeignKey(Page, editable=False) > item = models.ForeignKey(Item) # WANT THIS TO POINT TO SPECIFIC > SUBCLASS ITEM > position = models.IntegerField() > > def name(self): > return str(self.item.name) > > class Meta: > ordering = ['position'] > > # > ---------------------------------------------------------------------------------- > > class RadioBoxType(Item): > """A Radio Button object with its specific attributes""" > ......... etc. > > My problem is that I want the item/page relationship in the join table > PageItem, so I can track the position. I realize that I can't have a > fk to an abstract class though and obviously want it to point to the > subclassed object.
So point it at the subclass you want it to point at. If you mean, however, that you want it to point to one of a number of possible subclasses, depending on the instance, then that isn't a ForeignKey (a ForeignKey points to one particular model). What you're modelling in that case is best done with the GenericForeignKey, since that encodes both the content type (i.e. the model type) of the target as well as the primary key value. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---