Thanks, Richard - I thought about doing it this way, but I don't see how it could be integrated nicely into an admin form... you either have to create an Asset object for every new asset object, or you don't get the full list of possible assets in the Process admin form. I also don't like that a different Asset model would be required for every unique set of selectable content types (of which I have at least 3).
I know a GenericM2M can be done... possibly it's not even very hard. It's just that those RelatedObjectsDescriptors and ReverseRelatedObjectsDescriptors give me a headache, and I don't really understand how M2M works anyway (where is the code that creates the m2m table?) so I can't tackle it myself. Itai On 25/05/2008, at 2:31 AM, Richard Dahl wrote: > > Not sure if there is a better way (suggestions are appreciated), but I > just use the GenericForeignKey i.e.: > > class Asset(models.Model): > content_type = models.ForeignKey(AssetType) > object_id = models.PositiveIntegerField() > content_object = generic.GenericForeignKey('content_type', > 'object_id') > > class Process(models.Model): > [...] # irrelevant fields stripped > assets = models.ManyToManyField(Asset) > > I also use this to be able to limit what type of model can be related > in a generic way. I have a small subset of my total models that are > considered 'assets' (device, location, organization, etc...) The > AssetType table allows me to specify which of my models are considered > 'assets' . (This could probably be done with 'choices' within the > 'Asset' model, but I like the flexibility of another table.) > > class AssetType(models.Model): > type = models.ForeignKey(ContentType, unique=True) > > def __unicode__(self): > return ('%s' % (self.type.__unicode__().capitalize())) > > HTH, > -richard > > > > On May 24, 2008, at 2:55 AM, Itai Tavor wrote: > >> >> Hi, >> >> There was some talk about creating generic M2M fields around the end >> of '07, but I can't find any useful code. Has anyone got this >> working? >> >> Thanks, Itai >> >> >>> > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---