On Aug 3, 1:31 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> On Aug 3, 12:54 pm, Bram - Smartelectronix <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > hello all,
>
> > I have a generic relation Flag, with a FlagType:
>
> > class FlagType(models.Model):
> >      name = models.CharField(maxlength=50)
> >      description = models.TextField()
>
> > class Flag(models.Model):
> >      type = models.ForeignKey(FlagType) # type of flag
> >      content_type = models.ForeignKey(ContentType)
> >      object_id = models.PositiveIntegerField()
> >      content_object = generic.GenericForeignKey()
> >      user = models.ForeignKey(User)
> >      created = models.DateTimeField()
>
> > So, for example "illegal" or "to feature" would be flags. Now we're
> > flagging Song objects and I would like a queryset that gets me all Songs
> > flagged with a flag of type "illegal".
>
> > I can do:
>
> >    flag = FlagType.objects.get(name='illegal')
> >    ctype = ContentType.objects.get_for_model(Song)
> >    flagged = Flag.objects.filter(type=flag,
> >                content_type=ctype).order_by('-created')
> >    songs = [item.content_object for item in flagged ]
>
> > But the problem is: I can't do extra things to this list like order_by()
> > or an extra filter() or exclude().
>
> > How can I get the same result, but still have a queryset (containing
> > Songs) instead of a list??
>
> >   - bram
>
> songs = Song.objects.filter(id__in=[item.content_object.id for item in
> flagged])
>
> .. would hit the DB again .. but requires little code.
>
> Post back if another hit isn't a viable option and we'll take a closer
> look at the problem.

... item.object_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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to