views:

20

answers:

1

I have this Model in django :

class Post(models.Model):
    title = models.CharField(max_length=255)
    category = models.CharField(max_length=255)

I would like to get the different values that are used in the category attribute.

For example, if we consider this db :

Post(title = "title 1", category="foo")
Post(title = "title 2", category="bar")
Post(title = "title 3", category="foo")

the query should give me ("foo", "bar")

+2  A: 

Use distinct() and values_list():

Post.objects.values_list('category', flat=True).distinct();
Felix Kling
thanks!here is fore reference the django doc page http://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct
phmr