feat: make location string optional but enforce either location or location string

This commit is contained in:
2025-05-23 19:49:52 +02:00
parent 19d9dea8b1
commit 7a37377a09
2 changed files with 37 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
# Generated by Django 5.2.1 on 2025-05-23 16:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fellchensammlung', '0046_alter_importantlocation_location'),
]
operations = [
migrations.AlterField(
model_name='adoptionnotice',
name='further_information',
field=models.URLField(blank=True, help_text='Verlinke hier die Quelle der Vermittlung (z.B. die Website des Tierheims', null=True, verbose_name='Link zu mehr Informationen'),
),
migrations.AlterField(
model_name='adoptionnotice',
name='name',
field=models.CharField(max_length=200, verbose_name='Titel der Vermittlung'),
),
migrations.AlterField(
model_name='rescueorganization',
name='location_string',
field=models.CharField(blank=True, max_length=200, null=True, verbose_name='Ort der Organisation'),
),
]

View File

@@ -11,6 +11,7 @@ from django.dispatch import receiver
from django.db.models.signals import post_save from django.db.models.signals import post_save
from django.contrib.auth.models import Group from django.contrib.auth.models import Group
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from django.core.exceptions import ValidationError
from .tools import misc, geo from .tools import misc, geo
from notfellchen.settings import MEDIA_URL from notfellchen.settings import MEDIA_URL
@@ -131,7 +132,7 @@ class RescueOrganization(models.Model):
default=AllowUseOfMaterialsChices.USE_MATERIALS_NOT_ASKED, default=AllowUseOfMaterialsChices.USE_MATERIALS_NOT_ASKED,
choices=AllowUseOfMaterialsChices.choices, choices=AllowUseOfMaterialsChices.choices,
verbose_name=_('Erlaubt Nutzung von Inhalten')) verbose_name=_('Erlaubt Nutzung von Inhalten'))
location_string = models.CharField(max_length=200, verbose_name=_("Ort der Organisation")) location_string = models.CharField(max_length=200, verbose_name=_("Ort der Organisation"), null=True, blank=True, )
location = models.ForeignKey(Location, on_delete=models.PROTECT, blank=True, null=True) location = models.ForeignKey(Location, on_delete=models.PROTECT, blank=True, null=True)
instagram = models.URLField(null=True, blank=True, verbose_name=_('Instagram Profil')) instagram = models.URLField(null=True, blank=True, verbose_name=_('Instagram Profil'))
facebook = models.URLField(null=True, blank=True, verbose_name=_('Facebook Profil')) facebook = models.URLField(null=True, blank=True, verbose_name=_('Facebook Profil'))
@@ -153,6 +154,11 @@ class RescueOrganization(models.Model):
class Meta: class Meta:
unique_together = ('external_object_identifier', 'external_source_identifier',) unique_together = ('external_object_identifier', 'external_source_identifier',)
def clean(self):
super().clean()
if self.location is None and self.location_string is None:
raise ValidationError(_('Location or Location String must be set'))
def get_absolute_url(self): def get_absolute_url(self):
return reverse("rescue-organization-detail", args=[str(self.pk)]) return reverse("rescue-organization-detail", args=[str(self.pk)])
@@ -308,7 +314,8 @@ class AdoptionNotice(models.Model):
verbose_name=_('Organisation')) verbose_name=_('Organisation'))
further_information = models.URLField(null=True, blank=True, further_information = models.URLField(null=True, blank=True,
verbose_name=_('Link zu mehr Informationen'), verbose_name=_('Link zu mehr Informationen'),
help_text=_("Verlinke hier die Quelle der Vermittlung (z.B. die Website des Tierheims")) help_text=_(
"Verlinke hier die Quelle der Vermittlung (z.B. die Website des Tierheims"))
group_only = models.BooleanField(default=False, verbose_name=_('Ausschließlich Gruppenadoption')) group_only = models.BooleanField(default=False, verbose_name=_('Ausschließlich Gruppenadoption'))
photos = models.ManyToManyField(Image, blank=True) photos = models.ManyToManyField(Image, blank=True)
location_string = models.CharField(max_length=200, verbose_name=_("Ortsangabe")) location_string = models.CharField(max_length=200, verbose_name=_("Ortsangabe"))