# --------------------- # Artworks Models # --------------------- from django.contrib.gis.db import models from django.urls import reverse from django.contrib.contenttypes.models import ContentType from assets.models import AbstractLocation, AbstractAsset, AbstractGeoAsset, AbstractAssetModel from common.models import Municipality, Document from common.storages import PrivateMediaStorage private_storage = PrivateMediaStorage() # Road Street class ArtworkStreet(AbstractLocation): geom = models.MultiPolygonField(srid=3812, null=True,blank=True) municipality = models.ForeignKey(Municipality, on_delete=models.SET_NULL, null=True, blank=True, related_name="artworks_streets") road_code = models.CharField(max_length=50, null=True, blank=True) section_code = models.CharField(max_length=50, null=True, blank=True) street_level = models.CharField(max_length=50, null=True, blank=True) def get_active_assets(self): monuments = self.monuments.filter(status='active') fountains = self.fountains.filter(status='active') return { "monuments": monuments, "fountains": fountains, } def get_all_assets(self): monuments = self.monuments.all() fountains = self.fountains.all() return { "monuments": monuments, "fountains": fountains, } def get_direct_child_assets(self): monuments = self.monuments.all() fountains = self.fountains.all() return { "monuments": monuments, "fountains": fountains, } def get_absolute_url(self): return reverse("assets:artworks_streets_detail", kwargs={"street_id": self.id}) MONUMENT_TYPE_CHOICES = { 'bench': 'Banc public', 'construction': 'Construction', 'metal_structure': 'Structure métalique', 'monument': 'Monument', 'monumental_structure': 'Structure monumentale', 'pole': 'Poteau', 'sculpture': 'Sculpture', 'statue': 'Statue', 'structure': 'Structure', } # Monument class ArtworkMonument(AbstractGeoAsset): artist = models.CharField(max_length=200,null=True,blank=True) artwork_type = models.CharField(choices=MONUMENT_TYPE_CHOICES, max_length=100, null=True, blank=True) name_fr = models.CharField(max_length=200,null=True,blank=True) name_nl = models.CharField(max_length=200,null=True,blank=True) location_fr = models.CharField(max_length=500,null=True,blank=True) location_nl = models.CharField(max_length=500,null=True,blank=True) street = models.ForeignKey(ArtworkStreet, related_name="monuments", on_delete=models.SET_NULL, null=True, blank=True) water = models.BooleanField(default=False,null=True,blank=True) description_fr = models.TextField(null=True,blank=True) description_nl = models.TextField(null=True,blank=True) def get_absolute_url(self): # content_type = ContentType.objects.get_for_model(self.__class__) return reverse( 'assets:artworks_monuments_detail', kwargs={ # 'asset_model': content_type.model, 'asset_id': self.id } ) FOUNTAIN_TYPE_CHOICES = { 'monumental_artistic_fountain': 'Fontaine artistique monumentale', 'artistic_fountain': 'Fontaine artistique', 'monumental_fountain': 'Fontaine monumentale', 'artistic_play_fountain': 'Fontaine ludique artistique', 'play_fountain': 'Fontaine artistique', 'monumental_play_fountain': 'Fontaine ludique monumentale', } # Foutain class ArtworkFountain(AbstractGeoAsset): artist = models.CharField(max_length=200,null=True,blank=True) fountain_type = models.CharField(choices=FOUNTAIN_TYPE_CHOICES, max_length=100, null=True, blank=True) name_fr = models.CharField(max_length=200,null=True,blank=True) name_nl = models.CharField(max_length=200,null=True,blank=True) maintenance_contract = models.ForeignKey("contracts.Contract", on_delete=models.SET_NULL, null=True, blank=True) location_fr = models.CharField(max_length=500,null=True,blank=True) location_nl = models.CharField(max_length=500,null=True,blank=True) street = models.ForeignKey(ArtworkStreet, related_name="fountains", on_delete=models.SET_NULL, null=True, blank=True) description_fr = models.TextField(null=True,blank=True) description_nl = models.TextField(null=True,blank=True) def get_absolute_url(self): # content_type = ContentType.objects.get_for_model(self.__class__) return reverse( 'assets:artworks_fountains_detail', kwargs={ # 'asset_model': content_type.model, 'asset_id': self.id } ) class ArtworkFountainDocument(Document): fountain = models.ForeignKey(ArtworkFountain, on_delete=models.CASCADE, related_name="documents", verbose_name="Associated Fountain") file = models.FileField(upload_to="assets_documents/artworks/fountains/", storage=private_storage, verbose_name="Fichier", max_length=255) thumbnail = models.ImageField(upload_to="assets_documents/artworks/fountains/", storage=private_storage, null=True, blank=True, max_length=255) class ArtworkMonumentDocument(Document): fountain = models.ForeignKey(ArtworkMonument, on_delete=models.CASCADE, related_name="documents", verbose_name="Associated Monument") file = models.FileField(upload_to="assets_documents/artworks/fountains/", storage=private_storage, verbose_name="Fichier", max_length=255) thumbnail = models.ImageField(upload_to="assets_documents/artworks/fountains/", storage=private_storage, null=True, blank=True, max_length=255)