I’ve got a field in one model like: Now, I need to filter the objects by a date range. How do I filter all the objects that have a date between 1-Jan-2011 and 31-Jan-2011? Answer Use Or if you are just trying to filter month wise: Edit As Bernhard Vallant said, if you want a queryset which excludes the specified
Tag: django-queryset
Django Query That Get Most Recent Objects From Different Categories
I have two models A and B. All B objects have a foreign key to an A object. Given a set of A objects, is there anyway to use the ORM to get a set of B objects containing the most recent object created for each A object. Here’s an simplified example: So I’m looking for a query that returns
Get the index of an element in a queryset
I have a QuerySet, let’s call it qs, which is ordered by some attribute which is irrelevant to this problem. Then I have an object, let’s call it obj. Now I’d like to know at what index obj has in qs, as efficiently as possible. I know that I could use .index() from Python or possibly loop through qs comparing