Sorry, but select_related() dont work for you??

2013/1/23 Pankaj Singh <ps.j...@gmail.com>

> items = request.user. a11m1_user_itmes_set.all()
>
> is equivalent to
>
> items = A11M1_user_itmes.objects.filter(user=request.user)
>
> `items` will contain all items A11M1_user_itmes related to currently
> logged in user.
>
> Now, if you want to get `content_object` for a particular item, do
> something like following
>
> i = items[0]
>
> `i.content_object` will refer to original object used.
>
> Please go through official documentation for GenericForeignKey once more.
>
> Links:
> 1.
> https://docs.djangoproject.com/en/1.4/ref/contrib/contenttypes/#django.contrib.contenttypes.generic.GenericForeignKey
>
> --
> Pankaj Singh
> http://about.me/psjinx
>
>
> On Wed, Jan 23, 2013 at 4:11 PM, Sarfraz ahmad <sarfrazdja...@gmail.com>
> wrote:
> > i dont found any query related to this model bro........
> >
> >
> > On Wed, Jan 23, 2013 at 4:01 PM, Pankaj Singh <ps.j...@gmail.com> wrote:
> >>
> >> If you want to get all `A11M1_user_items` objects then following query
> >> should work
> >>
> >>
> >> --
> >> Pankaj Singh
> >> http://about.me/psjinx
> >>
> >>
> >> On Wed, Jan 23, 2013 at 3:53 PM, Sarfraz ahmad <sarfrazdja...@gmail.com
> >
> >> wrote:
> >> > i have the same model having one foreignkey to User and second to the
> >> > ContentType
> >> >
> >> > class A11M1_user_itmes(models.Model):
> >> >     A11M1F1_user=models.ForeignKey(User)
> >> >     content_type = models.ForeignKey(ContentType)
> >> >     object_id = models.PositiveIntegerField()
> >> >     content_object = generic.GenericForeignKey('content_type',
> >> > 'object_id')
> >> > this is the code of ma model...... using this code i wanna get all
> >> > objects
> >> > related to current logged in user
> >> >
> >> >
> >> > On Wed, Jan 23, 2013 at 3:38 PM, Pankaj Singh <ps.j...@gmail.com>
> wrote:
> >> >>
> >> >> So, you have a custom model like following
> >> >>
> >> >> class MyModel(models.Model):
> >> >>     ...
> >> >>     content_type = models.ForeignKey(ContentType)
> >> >>     ...
> >> >>
> >> >> And you want to run a query on MyModel which should return objects
> >> >> from various apps related to currently logged in User.
> >> >>
> >> >> Is this what you want to achieve?
> >> >>
> >> >> Pankaj Singh
> >> >> http://about.me/psjinx
> >> >>
> >> >>
> >> >> On Wed, Jan 23, 2013 at 3:29 PM, Sarfraz ahmad
> >> >> <sarfrazdja...@gmail.com>
> >> >> wrote:
> >> >> > thanx buddy bt i wish to do it in a manner that a model which has a
> >> >> > foreign
> >> >> > key to ContentType, when i make a query on this model it returns
> all
> >> >> > the
> >> >> > objects from various apps related to current logged in user
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> >> >> > On Wed, Jan 23, 2013 at 3:00 PM, Pankaj Singh <ps.j...@gmail.com>
> >> >> > wrote:
> >> >> >>
> >> >> >> Hey Sarfraz,
> >> >> >>
> >> >> >> If you have an user object, then you can get all related objects
> >> >> >> using
> >> >> >> following code
> >> >> >>
> >> >> >> user = User.objects.get(username="psjinx")
> >> >> >>
> >> >> >> related_links = [rel.get_accessor_name() for rel in
> >> >> >> user._meta.get_all_related_objects()]
> >> >> >>
> >> >> >> ## above code will give a list of attribute names for each related
> >> >> >> object to an user
> >> >> >> ## e.g. ['logentry_set', 'api_key', 'userprofile_set',
> >> >> >> 'recipient_set', 'customer']
> >> >> >>
> >> >> >> Now you can iterate over this list
> >> >> >>
> >> >> >> for link in related_links:
> >> >> >>     objects = getattr(user, link).all()
> >> >> >>     for object in objects:
> >> >> >>         ## do something with object
> >> >> >>
> >> >> >> FYI, getattr(user, link) is manager for that relate object.
> >> >> >>
> >> >> >>
> >> >> >> Pankaj Singh
> >> >> >> http://about.me/psjinx
> >> >> >>
> >> >> >>
> >> >> >> On Wed, Jan 23, 2013 at 2:42 PM, Pankaj Singh <ps.j...@gmail.com>
> >> >> >> wrote:
> >> >> >> > Hey Sarfraz,
> >> >> >> >
> >> >> >> > You can use any of following methods:
> >> >> >> >
> >> >> >> > User._meta.get_all_related_m2m_objects_with_model()
> >> >> >> > User._meta.get_all_related_objects()
> >> >> >> > User._meta.get_all_related_many_to_many_objects()
> >> >> >> > User._meta.get_all_related_objects_with_model()
> >> >> >> >
> >> >> >> > get_all_related_objects() is the one I guess you may want to use
> >> >> >> > in
> >> >> >> > your
> >> >> >> > case.
> >> >> >> >
> >> >> >> > Pankaj Singh
> >> >> >> > http://about.me/psjinx
> >> >> >> >
> >> >> >> >
> >> >> >> > On Wed, Jan 23, 2013 at 2:30 PM, Sarfraz ahmad
> >> >> >> > <sarfrazdja...@gmail.com>
> >> >> >> > wrote:
> >> >> >> >> hello friends
> >> >> >> >>                   i have a project with 7 applications
> installed
> >> >> >> >> in
> >> >> >> >> it
> >> >> >> >> and i
> >> >> >> >> want to get all the objects related to a particular user from
> all
> >> >> >> >> the
> >> >> >> >> applications of ma project......... please tell me how can i
> get
> >> >> >> >> all
> >> >> >> >> these
> >> >> >> >> objects using ContentType framework
> >> >> >> >>
> >> >> >> >>
> >> >> >> >> thank you all
> >> >> >> >>
> >> >> >> >> --
> >> >> >> >> 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/-/tKRQQKC06BsJ.
> >> >> >> >> 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.
> >> >>
> >> >> --
> >> >> 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.
> >>
> >
> > --
> > 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.
>
>


-- 
Rafael E. Ferrero
Claro: (03562) 15514856

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

Reply via email to