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
|
2021-09-25 20:31:08 +02:00
|
|
|
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,
|
2021-09-25 20:31:08 +02:00
|
|
|
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"]
|
2021-09-25 20:31:08 +02:00
|
|
|
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])
|