Hello,

I have to do a bit of a code rewrite and I want to measure twice and cut 
once with this. 

I need to store use extra information about each user, so I'm creating a 
profile. And each user can follow other users, so I create a ManyToMany 
field referencing the User model, and not "self" correct?

Like so:

 class Profile(models.Model):
   """Storing extra info about user"""
   name = models.OneToOneField(User, related_name='profile')
   moreinfo = models.TextField()
 
   friends = models.ManyToManyField(User, blank=True, through='Relationship',
   symmetrical=False,
   related_name='relationship')
 
 
 class Relationship(models.Model):
   from_user = models.ForeignKey(User, related_name='from_user')
   to_user = models.ForeignKey(User, related_name='to_user')
   rtype = models.TextField()
   moreinfo = models.TextField(null=True, blank=True)
 
 class Meta:
   unique_together = ('from_user', 'to_user')




*Rather than like so:*


 class Profile(models.Model):
   """Storing extra info about user"""
   name = models.OneToOneField(User, related_name='profile')
   moreinfo = models.TextField()
 
   friends = models.ManyToManyField(self, blank=True, through='Relationship',
   symmetrical=False,
   related_name='relationship')
 
 
 class Relationship(models.Model):
   from_user = models.ForeignKey(Profile, related_name='from_user')
   to_user = models.ForeignKey(Profile, related_name='to_user')
   rtype = models.TextField()
   moreinfo = models.TextField(null=True, blank=True)
 
 class Meta:
   unique_together = ('from_user', 'to_user')

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/efbefe7d-2d05-421a-a8b0-b64821a40750%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to