2012-05-23 4 views
1

Comment obtenir colonne spécifique du modèle Django (SELECT ville de liste) et comment afficher la ville répétée qu'une seule fois (je Londres x3)Comment obtenir une colonne spécifique du modèle dans Django?

Mon modèle:

class Advert(models.Model): 

    title = models.CharField(max_length=255) 
    company = models.CharField(max_length=255) 
    city = models.CharField(max_length=255) 
+0

https://docs.djangoproject.com/fr/1.4/topics/db/queries/ – rantanplan

Répondre

10

Essayez

Advert.objects.values('city').distinct() 

Ou

Advert.objects.values_list('city', flat=True).distinct() 

En outre, Vérification the doc est un must pour profiter de Django ORM QuerySet.

+0

Nice, merci! – pagepydj

Questions connexes