Re: Joining tables

2012-01-23 Thread Arun P
@bruno

Dint know that you can do lookups from OneToOne related models

Thanks

On Mon, Jan 16, 2012 at 8:00 PM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:

> On Jan 16, 8:04 am, Arun P  wrote:
> > Does this work?
> >
> > info =
> >
> ExtraInformation.objects.filter(user__is_active=1,user__is_staff=0,user__is_superuser=0).order_by("popularity").select_related("user")
> >
> > users = map(lambda i: i.user, info)
>
>
> That was for the "uselessly complicated and memory-hungry" method. Now
> for the "simple lazy" method:
>
> => users = User.objects.filter( here>).order_by("extrainformation__popularity")
>
> @OP : You can add a select_related if you plan on using data from
> ExtraInformation so you save on useless queries.
>
> --
> 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.
>
>


-- 
Digitally,
Arun Prabhakar 


-- 
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.



Re: Joining tables

2012-01-16 Thread bruno desthuilliers
On Jan 16, 8:04 am, Arun P  wrote:
> Does this work?
>
> info =
> ExtraInformation.objects.filter(user__is_active=1,user__is_staff=0,user__is_superuser=0).order_by("popularity").select_related("user")
>
> users = map(lambda i: i.user, info)


That was for the "uselessly complicated and memory-hungry" method. Now
for the "simple lazy" method:

=> users = User.objects.filter().order_by("extrainformation__popularity")

@OP : You can add a select_related if you plan on using data from
ExtraInformation so you save on useless queries.

-- 
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.



Re: Joining tables

2012-01-15 Thread Arun P
Does this work?

info =
ExtraInformation.objects.filter(user__is_active=1,user__is_staff=0,user__is_superuser=0).order_by("popularity").select_related("user")

users = map(lambda i: i.user, info)



Thanks

On Sun, Jan 15, 2012 at 1:05 AM, Swaroop Shankar V wrote:

> hello All,
> I have a model of following structure
>
> class ExtraInfomration():
>
> user = models.OneToOneField(User)
> total_likes = models.IntegerField(_('Total Likes'), null=True, blank=True,
> default=0)
> total_dislikes = models.IntegerField(_('Total Dislikes'), null=True,
> blank=True, default=0)
> popularity = models.FloatField(_('Popularity'), null=True, blank=True,
> default=0.0)
> created_on = models.DateTimeField(auto_now_add = True, null=True)
> updated_on = models.DateTimeField(auto_now=True)
>
> I have another model for profile. I need to retrieve users ordered by the
> popularity from the User model. This is the code am using to retrieve the
> users list
> userObject = User.objects.filter(is_active=1,is_staff=0,is_superuser=0)
>
> how can i order the data based on the popularity field in
> extrainformation? Thanks
>
> Regards,
>
> Swaroop Shankar V
>
>  --
> 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.
>



-- 
Digitally,
Arun Prabhakar 


-- 
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.



Joining tables

2012-01-14 Thread Swaroop Shankar V
hello All,
I have a model of following structure

class ExtraInfomration():

user = models.OneToOneField(User)
total_likes = models.IntegerField(_('Total Likes'), null=True, blank=True,
default=0)
total_dislikes = models.IntegerField(_('Total Dislikes'), null=True,
blank=True, default=0)
popularity = models.FloatField(_('Popularity'), null=True, blank=True,
default=0.0)
created_on = models.DateTimeField(auto_now_add = True, null=True)
updated_on = models.DateTimeField(auto_now=True)

I have another model for profile. I need to retrieve users ordered by the
popularity from the User model. This is the code am using to retrieve the
users list
userObject = User.objects.filter(is_active=1,is_staff=0,is_superuser=0)

how can i order the data based on the popularity field in extrainformation?
Thanks

Regards,

Swaroop Shankar V

-- 
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.



Re: Joining Tables

2012-01-08 Thread Swaroop Shankar V
Thanks a lot Anler, that's exactly what I want. I never knew that it was so
simple.

Thanks and Regards,
Swaroop Shankar V



On Sun, Jan 8, 2012 at 4:36 PM, Anler  wrote:

>  Oh sorry, it should be this:
>
> photos = Photos.objects.filter(user__groups__id=the_group_id)
>
> --
> Anler
> Sent with Sparrow 
>
> On Sunday, January 8, 2012 at 12:04 PM, Anler wrote:
>
>  Swaroop I think this is what you're asking for:
>
> photos = Photos.objects.filter(user__groups__name='admin')
>
> --
> Anler
> Sent with Sparrow 
>
> On Sunday, January 8, 2012 at 11:42 AM, Jonas Geiregat wrote:
>
>
>
> Thanks Jonas, the statements you had provided would give me a list of
> users who belong that group, but how can I retrieve the photos of those
> users? Actually I was looking for a single statement which would join all
> these tables and returns the data based on the Group ID.
>
>
> I would recommend reading through
> https://docs.djangoproject.com/en/dev/topics/db/queries/
>
> Getting a row by ID:
>
> Group.objects.get(pk=group_id)
>
> --
> 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.
>
>
>
>  --
> 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.
>

-- 
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.



Re: Joining Tables

2012-01-08 Thread Anler
Oh sorry, it should be this: 

photos = Photos.objects.filter(user__groups__id=the_group_id) 

-- 
Anler
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Sunday, January 8, 2012 at 12:04 PM, Anler wrote:

> Swaroop I think this is what you're asking for: 
> 
> photos = Photos.objects.filter(user__groups__name='admin') 
> 
> -- 
> Anler
> Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
> 
> 
> On Sunday, January 8, 2012 at 11:42 AM, Jonas Geiregat wrote:
> 
> > 
> > 
> > > Thanks Jonas, the statements you had provided would give me a list of 
> > > users who belong that group, but how can I retrieve the photos of those 
> > > users? Actually I was looking for a single statement which would join all 
> > > these tables and returns the data based on the Group ID.
> > 
> > I would recommend reading through 
> > https://docs.djangoproject.com/en/dev/topics/db/queries/
> > 
> > Getting a row by ID:
> > 
> > Group.objects.get(pk=group_id) 
> > 
> > -- 
> > 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 
> > (mailto:django-users@googlegroups.com).
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com 
> > (mailto:django-users+unsubscr...@googlegroups.com).
> > For more options, visit this group at 
> > http://groups.google.com/group/django-users?hl=en.
> 

-- 
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.



Re: Joining Tables

2012-01-08 Thread Anler
Swaroop I think this is what you're asking for: 

photos = Photos.objects.filter(user__groups__name='admin') 

-- 
Anler
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Sunday, January 8, 2012 at 11:42 AM, Jonas Geiregat wrote:

> 
> 
> > Thanks Jonas, the statements you had provided would give me a list of users 
> > who belong that group, but how can I retrieve the photos of those users? 
> > Actually I was looking for a single statement which would join all these 
> > tables and returns the data based on the Group ID.
> 
> I would recommend reading through 
> https://docs.djangoproject.com/en/dev/topics/db/queries/
> 
> Getting a row by ID:
> 
> Group.objects.get(pk=group_id) 
> 
> -- 
> 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 
> (mailto:django-users@googlegroups.com).
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com 
> (mailto:django-users+unsubscr...@googlegroups.com).
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

-- 
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.



Re: Joining Tables

2012-01-08 Thread Jonas Geiregat


> Thanks Jonas, the statements you had provided would give me a list of users 
> who belong that group, but how can I retrieve the photos of those users? 
> Actually I was looking for a single statement which would join all these 
> tables and returns the data based on the Group ID.

I would recommend reading through 
https://docs.djangoproject.com/en/dev/topics/db/queries/

Getting a row by ID:

Group.objects.get(pk=group_id)

-- 
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.



Re: Joining Tables

2012-01-08 Thread Swaroop Shankar V
Thanks Jonas, the statements you had provided would give me a list of users
who belong that group, but how can I retrieve the photos of those users?
Actually I was looking for a single statement which would join all these
tables and returns the data based on the Group ID.

Thanks and Regards,
Swaroop Shankar V



On Sun, Jan 8, 2012 at 2:34 PM, Jonas Geiregat  wrote:

>
>
> The user field is a foreign key to django auth User model. Each user is
> assigned to a group (django Auth Group model). I want to retrieve all the
> photos which belongs to users of a specific group. How can it be done?
>
>
> from django.contrib.auth.models import Group
>
> group = Group.objects.get(name='your_group')
> users = group.user_set.all()
>
> Haven't tested it, but I think that's what you want/need.
>
>
>  --
> 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.
>

-- 
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.



Re: Joining Tables

2012-01-08 Thread Jonas Geiregat


> The user field is a foreign key to django auth User model. Each user is 
> assigned to a group (django Auth Group model). I want to retrieve all the 
> photos which belongs to users of a specific group. How can it be done?
> 

from django.contrib.auth.models import Group

group = Group.objects.get(name='your_group')
users = group.user_set.all()

Haven't tested it, but I think that's what you want/need.


-- 
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.



Re: Joining Tables

2012-01-08 Thread Jonas Geiregat


> The user field is a foreign key to django auth User model. Each user is 
> assigned to a group (django Auth Group model). I want to retrieve all the 
> photos which belongs to users of a specific group. How can it be done?
> 

from django.contrib.auth.models import Group

group = Group.objects.get(name='your_group')
users = group.user_set.all()

Haven't tested it, but I think that's what you want/need.


-- 
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.



Joining Tables

2012-01-07 Thread Swaroop Shankar V
Hi,
I got a models which is as follows:

class Photos(models.Model):
"""
This model will enable the users to upload photos
"""
user = models.ForeignKey(User)
title = models.CharField(_('Title'), max_length=250, null = True, blank
= True)
description = models.TextField(_('Description'), null = True, blank =
True)
image = models.ImageField(_('Image'), upload_to=get_image_path)
created_on = models.DateTimeField(auto_now_add = True)
updated_on = models.DateTimeField(auto_now = True)

The user field is a foreign key to django auth User model. Each user is
assigned to a group (django Auth Group model). I want to retrieve all the
photos which belongs to users of a specific group. How can it be done?

Thanks and Regards,

Swaroop Shankar V

-- 
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.