Maybe you should check out generic foreign keys. Not sure if it's  
appropriate solution though.

Erik

On 16.09.2008, at 4:10, 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. Is there a better way to go about this or a work
> around anyone can point me at. Seems straight forward from an object
> perspective, maybe not for the ORM?
>
> My join table was working fine until I changed to the abstract
> supercalss (to solve another problem :-), and there are quite a few
> different item types.
>
> Any thoughts most appreciated. I am using django 1.0
>
> Thanks for listening,
>
> Peter
> >


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to