I am trying to figure out how to annotate with a count that is filtered. Here is a quick example of the situation and what I'm looking for:

models.py:

class A(models.Model):
    name = models.CharField(...)
    ...

class B(models.Model):
    date = models.DateField(null=False)
    ...

---
views.py
(proper imports)

def myview(request):
    <process/validate form>
    #here I would like to filter based on a date field from the form
    #let's call the form 'form' and the field 'date'
    a_qset = A.objects.annotate(before_val=Count(
                      'b__date__lte='+form.cleaned_data['date']))

---

Basically I want the number of B as of the date form.cleaned_data['date'] accessible in a queryset of As.

Now I know this code isn't correct (since I don't know the proper way to approach it) and is vastly simplified, but hopefully it gives an idea of what I want to do. Any suggestions are greatly appreciated.

Thanks!
Casey

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