2011-05-25 79 views
1

我需要創建一個帶有三列的model Class:網絡,畢業和職位(S)。ManyToMany上的基本Django模型問題

class UserProfile(models.Model): 
    network = models.ForeignKey(Network) 
    graduation = models.IntegerField(blank=True, null=True, choices=choices) 
    # position = ? 

我該如何進入職位列以允許多個職位(例如:藝術家,建築師,圖形藝術家)。請注意,這些職位在他們自己的表格中沒有任何相關信息。

回答

4

也許最好的辦法是繼續前進,有Position模型(有可能使用夾具來填充行):

class Position(models.Model): 
    label = models.CharField(max_length=100) 

    def __unicode__(self): 
     return self.label 

class UserProfile(models.Model): 
    [...] 
    positions = models.ManyToManyField(Position)