2021-08-22 20:10:29 +02:00
|
|
|
from django.db import models
|
|
|
|
from django.urls import reverse
|
|
|
|
from simple_history.models import HistoricalRecords
|
|
|
|
from sorl.thumbnail import ImageField
|
|
|
|
|
2021-08-29 22:09:22 +02:00
|
|
|
from common.models import BaseModel, DescriptionModel
|
2021-08-29 16:45:40 +02:00
|
|
|
from rpg_notes.settings import AUTH_USER_MODEL
|
2021-08-29 22:09:22 +02:00
|
|
|
from utils.colors import get_random_color, is_bright_color
|
2021-08-22 20:10:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Character(BaseModel, DescriptionModel):
|
|
|
|
subtitle = models.CharField(max_length=100, blank=True)
|
2021-08-29 16:45:40 +02:00
|
|
|
player = models.ForeignKey(AUTH_USER_MODEL, on_delete=models.PROTECT, blank=True, null=True)
|
2021-08-29 22:09:22 +02:00
|
|
|
# faction = models.ForeignKey(Faction, on_delete=models.PROTECT, blank=True, null=True)
|
|
|
|
# location = models.ForeignKey(Location, on_delete=models.PROTECT, blank=True, null=True)
|
2021-08-22 20:10:29 +02:00
|
|
|
color = models.CharField(max_length=6, default=get_random_color)
|
|
|
|
image = ImageField(upload_to="character_images", blank=True, null=True)
|
|
|
|
|
|
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
|
|
last_modified = models.DateTimeField(auto_now=True)
|
|
|
|
history = HistoricalRecords()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["name"]
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2021-08-29 00:20:02 +02:00
|
|
|
return reverse('characterdetail', args=[self.slug])
|
2021-08-22 20:10:29 +02:00
|
|
|
|
|
|
|
def initials(self):
|
|
|
|
return "".join([word[0] for word in self.name.split()][:2]).upper()
|
|
|
|
|
|
|
|
def text_color(self):
|
|
|
|
return "black" if is_bright_color(self.color) else "white"
|