Well a good session with my db made it apparent why this looked like it was working in Admin but not my other code - I had a join table pointing to the item superclasses, and thus their names showed up - OK - I feel even sillier now!
So, I am proceeding with the generic keys/relations and so far am not sure that the Admin is creating my supertype class properly when I create a subtype. Can anyone tell me if it should, or whether I need to hook the code and do something manually when I am creating these through the Admin. Sorry to keep bothering everyone. Peter On Sep 22, 12:34 pm, Peter Bailey <[EMAIL PROTECTED]> wrote: > Malcolm, (or any other knowledgeable soul), I have been experimenting > with bothabstractclasses and GenericForeignKeys 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. Theforeignkeyissue > 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 generickeywould 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 anabstractclass 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 -~----------~----~----~----~------~----~------~--~---