moviewyrm/fedireads/models/activity.py

40 lines
1.4 KiB
Python
Raw Normal View History

2020-02-11 23:17:21 +00:00
''' models for storing different kinds of Activities '''
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from model_utils.managers import InheritanceManager
2020-02-17 03:17:11 +00:00
from fedireads.utils.models import FedireadsModel
2020-02-11 23:17:21 +00:00
2020-02-17 03:17:11 +00:00
class Status(FedireadsModel):
''' any post, like a reply to a review, etc '''
user = models.ForeignKey('User', on_delete=models.PROTECT)
status_type = models.CharField(max_length=255, default='Note')
2020-02-17 02:45:25 +00:00
mention_users = models.ManyToManyField('User', related_name='mention_user')
mention_books = models.ManyToManyField('Book', related_name='mention_book')
activity_type = models.CharField(max_length=255, default='Note')
2020-02-15 22:38:46 +00:00
local = models.BooleanField(default=True)
privacy = models.CharField(max_length=255, default='public')
sensitive = models.BooleanField(default=False)
reply_parent = models.ForeignKey(
'self',
null=True,
on_delete=models.PROTECT
)
objects = InheritanceManager()
class Review(Status):
''' a book review '''
name = models.CharField(max_length=255)
book = models.ForeignKey('Book', on_delete=models.PROTECT)
rating = models.IntegerField(
default=0,
validators=[MinValueValidator(0), MaxValueValidator(5)]
)
2020-02-11 23:17:21 +00:00
def save(self, *args, **kwargs):
self.status_type = 'Review'
2020-02-11 23:17:21 +00:00
super().save(*args, **kwargs)