Malcolm, (or any other knowledgeable soul), I have been experimenting
with both abstract classes and Generic Foreign Keys and Relations to
solve my issues, and I still have some problems and questions. There
are not a lot of examples of those, and what I really need is for this
all to work properly in the admin so I can add a page and in the page
inline be able to add any sub-classed "Item". Can you tell me if that
type of functionality is supported in Admin yet with generic keys?

Also, I discovered my issue above when I was writing some backend code
to generate pages from the data collected in the Admin. The foreign
key issue then became apparent. One thing I am trying to wrap my head
around however is that when using my original model as above, the
Admin app handled everything correctly. I was able to add several
different item sub-types individually and attach them to pages without
problem, and everything seemed to work fine and things also seemed
correct in the database, So I guess I completely see the logic of why
a generic key would be required, but the Admin seems to work with what
I gave it correctly - I know it has a lot of magic, but I keep going
back and thinking if the Admin can work properly with this, there must
be a way that I can too. Very frustrating. Thoughts anyone (maybe I am
losing it :-) .....

Thanks again,

Peter


On Sep 16, 9:37 am, Peter Bailey <[EMAIL PROTECTED]> wrote:
> Thanks for the responses. There are a number of subclasses and I won't
> know the specifics initially. I'll check out the GenericForeighnKey.
> Sounds like it is what I want.
>
> Thanks again,
>
> Peter
>
> On Sep 16, 8:34 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
> wrote:
>
> > 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 asuperclass- 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 primarykeyvalue.
>
> > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to