Django Rest Framework模型关系

时间:2017-10-04 11:49:58

标签: django django-rest-framework models entity-relationship

我正在创建学校项目,图库应用。我有下一个实体:ProfileAlbumImageTagLikeComment。但我对关系有点困惑。我创造了所有,但我不确定一切都很好。请检查:

资料:

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)

你看起来怎么样?我错了吗?

0 个答案:

没有答案