On Fri, Jul 4, 2014 at 2:54 PM, Javier Guerra Giraldez <jav...@guerrag.com> wrote: > what purpose does the "container__item__previous__isnull=True" > argument serve here?
To filter on the initial item in the list. I'm looking for flag=True *only* on the first item in the list. flag=True could be set on other items in the same chain, but I don't care about those. The goal of the query is: I'm looking for all *current* items such that the *first item* in the chain has *flag = true*. In raw SQL I want the query to be: SELECT myapp_item.* FROM "myapp_item" INNER JOIN "myapp_container" ON ( "myapp_item"."container_id" = "myapp_container"."id" ) INNER JOIN "myapp_item" T3 ON ( "myapp_container"."id" = T3."container_id" ) WHERE ("myapp_item"."current" = True AND T3."previous_id" IS NULL AND T3."flag" = True ) So the WHERE condition flag=True, only applies to the initial item. >i think it means "an item that belongs to a container that has an item with no >'previous'" Correct, but not just any container, but the same container as the item being filtered. > which if it's a linked list, then any non-empty container would comply Right, except then the "container__item__flag=True" should influence it further. > and since you start the query from the item, then the container is non-empty > by definition. Yes, correct. > btw, a linked list in a database? can you elaborate on that idea? It is just one way to think about it. It is not really a linked list. I simply meant the items are linked together by the "previous" point. In my actual application item represent a step with history (previous being that history). Container represents the process of the step (has actual fields). So each step has a previous step in the process. Sometimes I want to query for the current step in the process based on the initial step. Cheers, Jon -- You received this message because you are subscribed to the Google Groups "Django developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CADhq2b7Uy6nY0Vo0__%2B3Ka1%2B_Hv7_smnJrDb4rtL%2B6sF%2B3QE5A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.