开发者

Basic django model question on ManyToMany

I 开发者_C百科need to create a model Class with three columns: network, graduation, and position(s).

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

How would I enter in the position column to allow for multiple positions (for example: artist, architect, graphic artist). Note that these positions will not have any related information in their own table.


Probably the best way is to go ahead and have a Position model (likely using fixtures to populate the rows):

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

    def __unicode__(self):
        return self.label

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜