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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---