feat: Add status, split migration to provide proper default

This commit is contained in:
moanos [he/him] 2024-05-31 15:57:38 +02:00
parent aa4c4d3c60
commit 195a5ab26a
3 changed files with 157 additions and 5 deletions

View File

@ -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,
),
),
],
),
]

View File

@ -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,
),
]

View File

@ -35,6 +35,64 @@ class Language(models.Model):
verbose_name_plural = _('Sprachen') 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): class Image(models.Model):
image = models.ImageField(upload_to='images') image = models.ImageField(upload_to='images')
alt_text = models.TextField(max_length=2000) alt_text = models.TextField(max_length=2000)
@ -62,7 +120,6 @@ class Species(models.Model):
class Location(models.Model): class Location(models.Model):
place_id = models.IntegerField() place_id = models.IntegerField()
latitude = models.FloatField() latitude = models.FloatField()
longitude = models.FloatField() longitude = models.FloatField()
@ -124,7 +181,8 @@ class AdoptionNotice(models.Model):
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"))
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 @property
def animals(self): def animals(self):
@ -199,8 +257,6 @@ class AdoptionNotice(models.Model):
return f"<a href='{self.further_information}'>{domain}</a>" return f"<a href='{self.further_information}'>{domain}</a>"
class Animal(models.Model): class Animal(models.Model):
MALE_NEUTERED = "M_N" MALE_NEUTERED = "M_N"
MALE = "M" MALE = "M"
@ -461,7 +517,6 @@ class Announcement(Text):
return active_announcements_in_language + untranslated_announcements return active_announcements_in_language + untranslated_announcements
class Comment(models.Model): class Comment(models.Model):
""" """
Class to store comments in markdown content Class to store comments in markdown content