2014-03-05 42 views
-2

model.py存儲在數據庫中的Django

class Venue(models.Model): 
    venue_Name = models.CharField(max_length=100) 
    place = models.CharField(max_length=50) 
    rent = models.IntegerField() 
    parking_area = models.IntegerField() 
    picture = models.ImageField(upload_to='images/', blank=True, null=True) 

    def __unicode__(self): 
     return self.venue_Name 

不同的值我要創建一個從場館類

+0

爲什麼你想這樣做?如果你需要不同的地方,只需在'Venue'上查詢獨特的地方。 – karthikr

+0

可以讓我那個代碼我不熟悉在Django – petes93

+0

查詢,我需要做這樣的事情:http://stackoverflow.com/questions/22186928/jquery-to-filter-the-content-being-printed-in -the-模板的Django – petes93

回答

1

爲了得到不同的地方,只是做一個不同的查詢:

Venue.objects.values_list('place', flat=True).distinct() 
0

我想你需要一個簡單的查詢來獲取存儲的地方唯一的不同值的另一模式在不同的地方:

你可以得到所有的場地對象與

Venue.objects.all() 

所以你可以過濾使用的地方:

def Distinct_Places(): 
    distinct_places = [] 
    for v in Venue.objects.all(): 
     if v.place not in distinct_places: 
      distinct_places.append(v.place) 
    return distinct_places 

希望它有幫助。

提示

您可能還需要看一看的Distinct QuerySet