Adding foreign key to User model
I'm sure there is an easy way to do this, but I can't seem to make it work. I need to add a couple foreign key references to the User model (defined in the admin application). I've imported the admin User, but it still fails to resolve it. Does it need to refered to it by it's full class name? from django.contrib.auth.models import User class Ticket(models.Model): created_by = models.ForeignKey("User", related_name="created_by_user_id") assigned_to = models.ForeignKey("User", related_name="assigned_to_user_id") Any help would be appreciated --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Custom linking of models in many-to-one relationship
I have a model that can be attached to a variety of different models, based on the value of a column. Is there any way to map this relationship in Django? If not, is there a way to automatically do post-fetch processing where I could populate it? Here is a example: class Note(models.Model): owner_id = models.IntegerField() #this is the FK of the related object owner_type = models.CharField(max_length=40) # this can either be "Account" or "Ticket" note = models.TextField() class Account(models.Model) name = models.CharField(max_length=40) ... class Ticket(models.Model) subject = models.CharField(max_length=120) ... So basically, we can attach Notes to either Account or Ticket. The "owner_id" field will be the primary key of the object being attached to. The "owner_type" will be either "Account" or "Ticket". When retrieving an Account, I want to also return all the Notes associated with it. I don't care about going the other direction in the relationship Is there any way to do this with the Django mappings? --~--~-~--~~~---~--~~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---