Use the aggregation way:
user.report_set.annotate(count = Count('report_set')).filter(count =
1)

On Sep 29, 10:39 pm, luismmontielg <luismmonti...@gmail.com> wrote:
> yeah, something like that is what I want, but to me, that is not the
> best way of doing it ...
> Maybe there's a simpler way?
>
> thanks in advance
>
> On Sep 29, 8:46 am, sunn <jo...@kolben.se> wrote:
>
> > This should hopefully work as well
> > user_reports = user.report_set.exclude(users__id__lt = user.id,
> > users_id_gt = user.id)
>
> > On Sep 29, 4:32 pm, sunn <jo...@kolben.se> wrote:
>
> > > If you don't want to write SQL I think the easiest way is to combine
> > > two querysets
>
> > > # You can combine queries with & and |.>>> s1 = 
> > > Article.objects.filter(id__exact=1)
> > > >>> s2 = Article.objects.filter(id__exact=2)
> > > >>> s1 | s2
>
> > > [<Article: Area woman programs in Python>, <Article: Second article>]>>> 
> > > s1 & s2
>
> > > []
>
> > > Fromhttp://www.djangoproject.com/documentation/models/basic/
>
> > > On Sep 29, 3:58 pm, luismmontielg <luismmonti...@gmail.com> wrote:
>
> > > > that brings me all reports that have that user, but also the reports
> > > > that have user and user2.. i want only the reports that have 1 user
> > > > and id is equal to user.id
>
> > > > On Sep 29, 4:35 am, Joshua Russo <josh.r.ru...@gmail.com> wrote:
>
> > > > > oh ok, so just use the filter(user_id = user.id)
>
> > > > > On Tue, Sep 29, 2009 at 12:21 AM, luismmontielg 
> > > > > <luismmonti...@gmail.com>wrote:
>
> > > > > > Actually there it is,
>
> > > > > > users = models.ManyToManyField(User, symmetrical=True)
>
> > > > > > but I want to filter only the reports that contain only this user, 
> > > > > > or
> > > > > > exclude the ones that do not have the user.
>
> > > > > > Thanks again
>
> > > > > > On 28 sep, 20:16, luismmontielg <luismmonti...@gmail.com> wrote:
> > > > > > > sorry forgot to mention its a many to many relation so a report 
> > > > > > > can
> > > > > > > have multiple users
>
> > > > > > > On Sep 28, 4:29 pm, Joshua Russo <josh.r.ru...@gmail.com> wrote:
>
> > > > > > > > On Mon, Sep 28, 2009 at 7:55 PM, luismmontielg <
> > > > > > luismmonti...@gmail.com>wrote:
>
> > > > > > > > > Hello,
> > > > > > > > > I have my models like this...
>
> > > > > > > > > class Report(models.Model):
> > > > > > > > >    title = models.CharField(max_length=50, blank=True)
> > > > > > > > >    users = models.ManyToManyField(User, symmetrical=True)
> > > > > > > > >    categories = models.ManyToManyField("Category",
> > > > > > > > > through='ReportDetail', \
> > > > > > > > >                 symmetrical=True)
>
> > > > > > > > > I would like to get all reports from 1 user, but that only 
> > > > > > > > > contain
> > > > > > > > > that user
>
> > > > > > > > > I was looking for ne, not equals, but its removed, I cant do 
> > > > > > > > > it with
> > > > > > > > > the exclude:
> > > > > > > > > I want to make something like this
> > > > > > > > > user = User.objects.get(pk=1)
> > > > > > > > > user_reports = user.report_set.exclude(users__id__NOTEQUAL = 
> > > > > > > > > user.id
> > > > > > )
>
> > > > > > > > > how can I achieve this?
>
> > > > > > > > I'm not sure I completely follow, but user.report_set only 
> > > > > > > > gives you
> > > > > > reports
> > > > > > > > for the associated user, and it seems like that is what you 
> > > > > > > > want. You
> > > > > > don't
> > > > > > > > need any further filters or excludes.
>
> > > > > > > > For future reference:
> > > > > > > >     exclude(user_id__ne = user.id)
> > > > > > > > is the same as
> > > > > > > >     filter(user_id = user.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
-~----------~----~----~----~------~----~------~--~---

Reply via email to