我正在创建学校项目,图库应用。我有下一个实体:Profile
,Album
,Image
,Tag
,Like
,Comment
。但我对关系有点困惑。我创造了所有,但我不确定一切都很好。请检查:
class Profile(models.Model):
user = models.OneToOneField(User)
albums = models.ManyToManyField("albums.Album", blank=True)
commented = models.ManyToManyField("comments.Comment", blank=True, unique=False)
liked = models.ManyToManyField("likes.Like", blank=True)
profile_picture = models.ImageField( blank=True, null=True, upload_to='profile_pics')
timestamp = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class Album(models.Model):
name = models.CharField(max_length=120, blank=False, null=False)
owner = models.ForeignKey("profiles.Profile")
description = models.TextField( max_length=500, null=True)
images = models.ManyToManyField("images.Image", related_name="album_images", blank=True)
is_public = models.BooleanField(default=False)
timestamp = models.DateField(auto_now_add=True)
updated = models.DateField(auto_now=True)
class Image(models.Model):
name = models.CharField(max_length=120, blank=False, null=True)
album = models.ForeignKey("albums.Album", related_name="album_id", null=True, blank=True)
image = models.ImageField(verbose_name="Image", blank=True, null=True, upload_to='img')
description = models.TextField(max_length=500, null=True, blank=True)
comments = models.ManyToManyField("comments.Comment", related_name="all_comments", blank=True, unique=False)
likes = models.ManyToManyField("likes.Like", related_name="all_likes", blank=True, unique=False)
tags = models.ManyToManyField("tags.Tag", related_name="all_tags", blank=True)
is_public = models.BooleanField(default=False)
timestamp = models.DateField(auto_now_add=True)
updated = models.DateField(auto_now=True)
class Tag(models.Model):
name = models.CharField(max_length=120, blank=False, null=False)
images = models.ManyToManyField("images.Image", blank=True)
timestamp = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class Like(models.Model):
owner = models.ManyToManyField("profiles.Profile")
image = models.ManyToManyField("images.Image")
timestamp = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
class Comment(models.Model):
owner = models.ManyToManyField("profiles.Profile", unique=False)
image = models.ManyToManyField("images.Image", unique=False)
content = models.TextField(max_length=500, blank=False, null=False)
timestamp = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
你看起来怎么样?我错了吗?