0
我想为我的Django应用程序构建正确的模型。我正在尝试构建一些内容,允许用户将URL保存到与该用户绑定的一个(或多个)播放列表中。在我实现这个之前,我想确保这是构建我的models.py的最佳方式。构建models.py的正确方法是什么?
class UserProfile(models.Model):
user = models.ForeignKey(User, primary_key=True) #what is the difference between ForeignKey and OneToOne? Which one should I use?
Playlist = models.CharField('Playlist', max_length = 2000) #1 user should be able to have multiple playlists and the default playlist should be "Favorites"
def __unicode__(self):
return self.User
class Videos(models.Model):
Video_url = models.URLField('Link to video', max_length = 200, null=True, blank=True)
Playlist = models.ManyToManyField(Playlist) #this should connect to the playlists a user has. A user should be able to save any video to any plalist, so perhaps this should be ManyToMany?
def __unicode__(self):
return self.Video_url
ForeignKey的区别和OneToOne http://stackoverflow.com/questions/5870537/whats-the-difference-between-django-onetoonefield-and-foreignkey – iMom0
@ iMom0什么关于其他问题?你认为这是我想要启用的正确方法吗? – sharataka