I want to be able to link one model to another model, regardless of what models they are. Articles can be related to Photos, Videos, other Articles, etc etc etc.
I have created a Relationship model to represent these relationships, but I'm unsure if this is the best solution. First off, my requirements include having a title, description, type, and priority to further describe the relationship. Secondly, I am using UUIDs for primary keys so I created a custom field to represent this (postgresql has a UUID field as well). Thirdly, I don't plan on using the out-of-box admin console, so whether or not a particular pattern works well in the admin console or not is not relevant for me. The following model accurately represents what I need, and in theory it works well. I can now have an abstract model that all my other models inherit, with an addRelationship(self, destination) method and various other methods to fetch relationships. In this abstract class, I also have this: from django.contrib.contenttypes.models import ContentType class Abstract(models.Model): ... def getType(self): if (self._type == None): self._type = ContentType.objects.get_for_model(self) return self._type In order to make my life easier, as you'll see in my model below. I would like opinions about my approach, I am new to python, and newer still to Django. There might be things I am overlooking due to my ignorance. class Relationship(models.Model): id = fields.UUID(auto_add=True,primary_key=True, unique=True) created_by = fields.UUID(db_index=True,null=True,blank=True) created_on = models.DateField(auto_now=False,auto_now_add=True) modfied_on = models.DateField(auto_now=True,auto_now_add=False) title = models.CharField(max_length=255) source_id = fields.UUID(db_index=True) source_app_label = models.CharField(db_index=True,max_length=255) source_model = models.CharField(db_index=True,max_length=255) destination_id = fields.UUID(db_index=True) destination_app_label = models.CharField(db_index=True,max_length=255) destination_model = models.CharField(db_index=True,max_length=255) description = models.TextField(null=True,blank=True) type = models.CharField(max_length=64,null=True,blank=True,db_index=True) priority = models.PositiveIntegerField() Thanks in advance... -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.