1
0
Fork 0
mirror of https://github.com/Findus23/RPGnotes.git synced 2024-09-19 15:43:45 +02:00
RPGnotes/locations/models.py

38 lines
1.1 KiB
Python
Raw Normal View History

2021-09-06 20:34:43 +02:00
from django.db import models
2021-09-15 16:51:43 +02:00
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
2021-10-07 22:58:17 +02:00
from sorl.thumbnail import ImageField
2021-09-15 16:51:43 +02:00
from tree_queries.fields import TreeNodeForeignKey
from tree_queries.models import TreeNode
2022-07-05 18:37:21 +02:00
from common.models import NameSlugModel, DescriptionModel, HistoryModel, AliasModel
2022-04-11 22:43:06 +02:00
from search.utils import NameSearchIndex
2021-10-07 22:58:17 +02:00
from utils.random_filename import get_file_path
2021-09-15 16:51:43 +02:00
2022-07-05 18:37:21 +02:00
class Location(TreeNode, NameSlugModel, DescriptionModel, AliasModel, HistoryModel):
2021-09-15 16:51:43 +02:00
parent = TreeNodeForeignKey(
"self",
blank=True,
null=True,
on_delete=models.CASCADE,
verbose_name=_("Part of"),
2021-09-15 16:51:43 +02:00
related_name="children",
)
2021-10-07 22:58:17 +02:00
image = ImageField(_("Image"), upload_to=get_file_path, blank=True, null=True)
2021-09-06 20:34:43 +02:00
2021-09-15 16:51:43 +02:00
class Meta:
ordering = ["name"]
verbose_name = _("Location")
verbose_name_plural = _("Locations")
2022-04-11 22:43:06 +02:00
indexes = [
NameSearchIndex
]
2021-09-06 20:34:43 +02:00
2021-09-15 16:51:43 +02:00
def get_absolute_url(self):
return reverse('locationdetail', args=[self.slug])
2022-11-19 22:09:15 +01:00
@property
def graphkey(self):
return f"loc{self.pk}"