I know exactly what I want to do in raw SQL (see blue below), but can't figure out how to get it using python in django.
I'm trying to create a "my friends" page, which will list the user's friends listed in alphabetical order.
I have two classes involved with this data: Profile [and] Friendship
class Friendship(models.Model):
friend = models.ForeignKey(User, related_name='friend1')
friendwith = models.ForeignKey(User, related_name='friend2')
class Profile(models.Model):
user = models.OneToOneField(User,
unique=True,
verbose_name=_('user'),
related_name='profile')
first_name = models.TextField(max_length=50)
last_name = models.TextField(max_length=50)
The exact raw SQL query [successfully tested] is as follows::
select profiles_profile.first_name,profiles_profile.last_name FROM profiles_profile, friends_friendship WHERE profiles_profile.user_id = friends_friendship.friendwith_id AND friends_friendship.friend_id = 30 ORDER BY first_name ASC;
My problem is I'm not sure how to do this in Python.
'30' is the user's id/pk.
Any help is GREATLY appreciated!!
- Keith
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/YqHU7w7yVBgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment