views:

54

answers:

1

Hello

Assume I have such simple model:

class Foo(models.Model):
    name = models.CharField(max_length=25)
    b_date = models.DateField()

Now assume that my query result from Foo.objects.all() , I retrieve something like this:

[
    {'name': 'zed', 'b_date': '2009-12-23'},
    {'name': 'amy', 'b_date': '2009-12-6'},
    {'name': 'joe', 'b_date': '2009-12-26'},
    {'name': 'wayne', 'b_date': '2009-12-14'},
    {'name': 'chris', 'b_date': '2009-12-9'},
]

Now I need to get the earliest date from b_date (which is '2009-12-6' for our case and the latest one ('2009-12-23' for the example) and generate a list that start from the begining and iterates through the end such as:

what_I_want = ['2009-12-6','2009-12-7','2009-12-8' .............. '2009-12-22','2009-12-23']

How would you solve this, in the most efficient way. doing this either in view or templete would be appreciated.

Regards

+7  A: 
Foo.objects.order_by('b_date').values_list('b_date', flat=True)
Ignacio Vazquez-Abrams