2011-05-25 76 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)