diff --git a/src/fellchensammlung/migrations/0010_status.py b/src/fellchensammlung/migrations/0010_status.py new file mode 100644 index 0000000..6d69e8f --- /dev/null +++ b/src/fellchensammlung/migrations/0010_status.py @@ -0,0 +1,70 @@ +# Generated by Django 5.0.6 on 2024-06-06 14:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("fellchensammlung", "0009_remove_image_title"), + ] + + operations = [ + migrations.CreateModel( + name="Status", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "major_status", + models.CharField( + choices=[ + ("active", "active"), + ("in_review", "in review"), + ("closed", "closed"), + ("disabled", "disabled"), + ], + max_length=200, + ), + ), + ( + "minor_status", + models.CharField( + choices=[ + ("searching", "searching"), + ("interested", "interested"), + ("waiting_for_review", "waiting_for_review"), + ( + "successful_with_notfellchen", + "successful_with_notfellchen", + ), + ( + "successful_without_notfellchen", + "successful_without_notfellchen", + ), + ("animal_died", "animal_died"), + ( + "closed_for_other_adoption_notice", + "closed_for_other_adoption_notice", + ), + ( + "not_open_for_adoption_anymore", + "not_open_for_adoption_anymore", + ), + ("other", "other"), + ("against_the_rules", "against_the_rules"), + ("missing_information", "missing_information"), + ], + max_length=200, + ), + ), + ], + ), + ] diff --git a/src/fellchensammlung/migrations/0011_adoptionnotice_status.py b/src/fellchensammlung/migrations/0011_adoptionnotice_status.py new file mode 100644 index 0000000..14613e3 --- /dev/null +++ b/src/fellchensammlung/migrations/0011_adoptionnotice_status.py @@ -0,0 +1,27 @@ +# Generated by Django 5.0.6 on 2024-06-06 14:51 + +import django.db.models.deletion +from django.db import migrations, models + +from fellchensammlung.models import Status + +default_status = Status.objects.create(major_status=Status.ACTIVE, minor_status="searching") + + +class Migration(migrations.Migration): + dependencies = [ + ("fellchensammlung", "0010_status"), + ] + + operations = [ + migrations.AddField( + model_name="adoptionnotice", + name="status", + field=models.ForeignKey( + default=default_status.pk, + on_delete=django.db.models.deletion.PROTECT, + to="fellchensammlung.status", + ), + preserve_default=False, + ), + ] diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index ad7a91d..a1aea86 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -35,6 +35,64 @@ class Language(models.Model): verbose_name_plural = _('Sprachen') +class Status(models.Model): + """ + The major status indicates a general state of an adoption notice + whereas the minor status is used for reporting + """ + + ACTIVE = "active" + IN_REVIEW = "in_review" + CLOSED = "closed" + DISABLED = "disabled" + MAJOR_STATUS_CHOICES = { + ACTIVE: "active", + IN_REVIEW: "in review", + CLOSED: "closed", + DISABLED: "disabled", + } + + MINOR_STATUS_CHOICES = { + ACTIVE: { + "searching": "searching", + "interested": "interested", + }, + IN_REVIEW: { + "waiting_for_review": "waiting_for_review", + }, + CLOSED: { + "successful_with_notfellchen": "successful_with_notfellchen", + "successful_without_notfellchen": "successful_without_notfellchen", + "animal_died": "animal_died", + "closed_for_other_adoption_notice": "closed_for_other_adoption_notice", + "not_open_for_adoption_anymore": "not_open_for_adoption_anymore", + "other": "other" + }, + DISABLED: { + "against_the_rules": "against_the_rules", + "missing_information": "missing_information", + "other": "other" + } + } + + major_status = models.CharField(choices=MAJOR_STATUS_CHOICES, max_length=200) + minor_choices = {} + for key in MINOR_STATUS_CHOICES: + minor_choices.update(MINOR_STATUS_CHOICES[key]) + minor_status = models.CharField(choices=minor_choices, max_length=200) + + def __str__(self): + return f"{self.major_status}: {self.minor_status}" + + @property + def is_active(self): + return self.major_status == self.ACTIVE + + @staticmethod + def get_minor_choices(major_status): + return Status.MINOR_STATUS_CHOICES[major_status] + + class Image(models.Model): image = models.ImageField(upload_to='images') alt_text = models.TextField(max_length=2000) @@ -62,7 +120,6 @@ class Species(models.Model): class Location(models.Model): - place_id = models.IntegerField() latitude = models.FloatField() longitude = models.FloatField() @@ -124,7 +181,8 @@ class AdoptionNotice(models.Model): group_only = models.BooleanField(default=False, verbose_name=_('Ausschließlich Gruppenadoption')) photos = models.ManyToManyField(Image, blank=True) location_string = models.CharField(max_length=200, verbose_name=_("Ortsangabe")) - location = models.ForeignKey(Location, blank=True, null=True, on_delete=models.SET_NULL,) + location = models.ForeignKey(Location, blank=True, null=True, on_delete=models.SET_NULL, ) + status = models.ForeignKey(Status, on_delete=models.PROTECT) @property def animals(self): @@ -199,8 +257,6 @@ class AdoptionNotice(models.Model): return f"{domain}" - - class Animal(models.Model): MALE_NEUTERED = "M_N" MALE = "M" @@ -461,7 +517,6 @@ class Announcement(Text): return active_announcements_in_language + untranslated_announcements - class Comment(models.Model): """ Class to store comments in markdown content