lib.itmens/users/models.py

38 lines
1.4 KiB
Python
Raw Normal View History

2020-05-05 23:50:48 +08:00
import uuid
2020-05-01 22:46:15 +08:00
from django.db import models
from django.contrib.auth.models import AbstractUser
2020-05-05 23:50:48 +08:00
from django.utils import timezone
2020-05-01 22:46:15 +08:00
from boofilsic.settings import REPORT_MEDIA_PATH_ROOT, DEFAULT_PASSWORD
def report_image_path(instance, filename):
2020-05-05 23:50:48 +08:00
ext = filename.split('.')[-1]
filename = "%s.%s" % (uuid.uuid4(), ext)
2020-05-01 22:46:15 +08:00
root = ''
if REPORT_MEDIA_PATH_ROOT.endswith('/'):
root = REPORT_MEDIA_PATH_ROOT
else:
root = REPORT_MEDIA_PATH_ROOT + '/'
2020-05-05 23:50:48 +08:00
return root + timezone.now().strftime('%Y/%m/%d') + f'{filename}'
2020-05-01 22:46:15 +08:00
class User(AbstractUser):
2020-05-05 23:50:48 +08:00
mastodon_id = models.IntegerField(unique=True)
2020-05-01 22:46:15 +08:00
def save(self, *args, **kwargs):
""" Automatically populate password field with DEFAULT_PASSWORD before saving."""
self.set_password(DEFAULT_PASSWORD)
return super().save(*args, **kwargs)
class Report(models.Model):
submit_user = models.ForeignKey(User, on_delete=models.SET_NULL, related_name='sumbitted_reports', null=True)
reported_user = models.ForeignKey(User, on_delete=models.SET_NULL, related_name='accused_reports', null=True)
image = models.ImageField(upload_to=report_image_path, height_field=None, width_field=None, max_length=None, blank=True, default='')
is_read = models.BooleanField(default=False)
submitted_time = models.DateTimeField(auto_now_add=True)
2020-05-05 23:50:48 +08:00
message = models.CharField(max_length=1000)
2020-05-01 22:46:15 +08:00