开发者

Django: how can i assosiate multiple groups to one file?

I have a "File" table which could have multiple groups associated with it. How can i implement that with django?

groups = models.ForeignKey(Group)

This will enable me to only have one group for each file. I thought about creating a CharField with group names separated by 开发者_如何学Pythona colon or a comma if there's no other way.


Use many-to-many relationship

eg:

class File(models.Model):
    ...

class Group(models.Model):
    files = models.ManyToManyField(File, related_name='groups')
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜