2021-01-01 18:46:15 +00:00
|
|
|
''' like/fav/star a status '''
|
|
|
|
from django.db import models
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
from bookwyrm import activitypub
|
2021-02-04 22:36:57 +00:00
|
|
|
from .activitypub_mixin import ActivityMixin
|
2021-02-04 18:47:03 +00:00
|
|
|
from .base_model import BookWyrmModel
|
2021-01-01 18:46:15 +00:00
|
|
|
from . import fields
|
|
|
|
|
2021-02-04 22:36:57 +00:00
|
|
|
class Favorite(ActivityMixin, BookWyrmModel):
|
2021-01-01 18:46:15 +00:00
|
|
|
''' fav'ing a post '''
|
|
|
|
user = fields.ForeignKey(
|
|
|
|
'User', on_delete=models.PROTECT, activitypub_field='actor')
|
|
|
|
status = fields.ForeignKey(
|
|
|
|
'Status', on_delete=models.PROTECT, activitypub_field='object')
|
|
|
|
|
|
|
|
activity_serializer = activitypub.Like
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
''' update user active time '''
|
|
|
|
self.user.last_active_date = timezone.now()
|
2021-02-06 20:00:47 +00:00
|
|
|
self.user.save(broadcast=False)
|
2021-01-01 18:46:15 +00:00
|
|
|
super().save(*args, **kwargs)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
''' can't fav things twice '''
|
|
|
|
unique_together = ('user', 'status')
|