Gallery-Archivist/archivist/apps/user/models.py
2024-06-25 22:24:59 +02:00

44 lines
1.3 KiB
Python

from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import gettext_lazy as _
from apps.sites.models import Submissions
class UserProfile(models.Model):
MATURE = [
("H", "Hide"),
("B", "Blur"),
("S", "Show"),
]
ITEMS_PER_PAGE = [
(24, "24"),
(48, "48"),
(72, "72"),
]
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True, unique=True)
show_mature = models.CharField(max_length=2, choices=MATURE, default=MATURE[0][0])
items_per_page = models.IntegerField(choices=ITEMS_PER_PAGE, default=ITEMS_PER_PAGE[0][0])
class Meta:
verbose_name = _("User Profile")
verbose_name_plural = _("User Profiles")
def __str__(self):
return self.user.username
class SeenPost(models.Model):
user = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
post = models.ForeignKey(Submissions, on_delete=models.CASCADE)
timestamp = models.DateTimeField(auto_now_add=True)
class Meta:
verbose_name = _("Seen Post")
verbose_name_plural = _("Seen Posts")
def __str__(self) -> str:
return self.user.user.username + " - " + self.post.submission_hash