Gallery-Archivist/backend/apps/archive/models.py

85 lines
2.6 KiB
Python

from django.db import models
from apps.files.models import PostFileModel
class SourceSiteModel(models.Model):
slug = models.CharField(max_length=64)
name = models.CharField(max_length=64)
date_last_import = models.DateTimeField(auto_now=True)
date_created = models.DateTimeField(auto_now_add=True)
class Meta:
verbose_name = "Source Site"
verbose_name_plural = "Source Sites"
def __str__(self):
if self.name:
return str(self.name)
else:
return str(self.slug)
class CategoryModel(models.Model):
slug = models.CharField(max_length=64)
name = models.CharField(max_length=64)
date_modified = models.DateTimeField(auto_now=True)
date_created = models.DateTimeField(auto_now_add=True)
class Meta:
verbose_name = "Category"
verbose_name_plural = "Categories"
def __str__(self):
if len(str(self.name)) > 0:
return str(self.name)
else:
return str(self.slug)
class DescriptionModel(models.Model):
hash = models.CharField(max_length=128)
content = models.TextField()
date_modified = models.DateTimeField(auto_now=True, editable=True)
date_created = models.DateTimeField(auto_now_add=True, editable=True)
class Meta:
verbose_name = "Description"
verbose_name_plural = "Descriptions"
def __str__(self):
return str(self.hash)
class PostModel(models.Model):
post_id = models.CharField(max_length=128, db_index=True)
title = models.CharField(max_length=64)
description = models.ManyToManyField(
to=DescriptionModel, related_name="posts", through=PostDescription
)
creator = models.ForeignKey(
to=CreatorModel,
on_delete=models.CASCADE,
null=True,
blank=True,
related_name="posts",
)
source_site = models.ForeignKey(
to=SourceSiteModel, on_delete=models.CASCADE, related_name="posts"
)
category = models.ManyToManyField(to=CategoryModel, related_name="posts")
tags = models.ManyToManyField(to=TagModel, related_name="posts")
mature = models.BooleanField(default=False)
files = models.ManyToManyField(to=PostFileModel, related_name="posts")
date_created = models.DateTimeField(auto_now_add=True, editable=True)
date_imported = models.DateTimeField(auto_now_add=True, editable=True)
date_last_import = models.DateTimeField(auto_now=True, editable=True)
class Meta:
verbose_name = "Post"
verbose_name_plural = "Posts"
def __str__(self):
return str(self.title)