diff --git a/src/fellchensammlung/admin.py b/src/fellchensammlung/admin.py index cf4af59..12ee258 100644 --- a/src/fellchensammlung/admin.py +++ b/src/fellchensammlung/admin.py @@ -5,7 +5,7 @@ from django.utils.html import format_html from .models import User, Language, Text, ReportComment, ReportAdoptionNotice from .models import Animal, Species, RescueOrganization, AdoptionNotice, Location, Rule, Image, ModerationAction, \ - Member, Comment, Report, Announcement + Member, Comment, Report, Announcement, AdoptionNoticeStatus # Define an inline admin descriptor for Employee model @@ -21,6 +21,17 @@ class UserAdmin(BaseUserAdmin): inlines = [MemberInline] +class StatusInline(admin.StackedInline): + model = AdoptionNoticeStatus + + +@admin.register(AdoptionNotice) +class AdoptionNoticeAdmin(admin.ModelAdmin): + inlines = [ + StatusInline, + ] + + # Re-register UserAdmin admin.site.register(User, UserAdmin) @@ -56,10 +67,10 @@ admin.site.register(Animal) admin.site.register(Species) admin.site.register(RescueOrganization) admin.site.register(Location) -admin.site.register(AdoptionNotice) admin.site.register(Rule) admin.site.register(Image) admin.site.register(ModerationAction) admin.site.register(Language) admin.site.register(Text) admin.site.register(Announcement) +admin.site.register(AdoptionNoticeStatus) diff --git a/src/fellchensammlung/baker_recipes.py b/src/fellchensammlung/baker_recipes.py index a4e99db..a4e338b 100644 --- a/src/fellchensammlung/baker_recipes.py +++ b/src/fellchensammlung/baker_recipes.py @@ -4,9 +4,10 @@ from fellchensammlung.models import * location = Recipe( Location, - name=seq('Ort_'), - description=seq('Detaillierte Beschreibung_'), - postcode=seq("7322"), + place_id=seq(''), + name=seq('Location_'), + longitude=seq(""), + latitude=seq(""), ) rescue_org = Recipe( diff --git a/src/fellchensammlung/management/commands/populate_db.py b/src/fellchensammlung/management/commands/populate_db.py index 368218c..db01611 100644 --- a/src/fellchensammlung/management/commands/populate_db.py +++ b/src/fellchensammlung/management/commands/populate_db.py @@ -35,7 +35,7 @@ class Command(BaseCommand): # Check if there already is and AdoptionNotice named Vermittung1TestSalt9227. If it is, the database # is already populated and no data will be added again try: - AdoptionNotice.objects.get(name="Vermittung1TestSalt9227") + AdoptionNotice.objects.get(name="Vermittlung1TestSalt9227") print("Database already populated. No additional data will be created") return except AdoptionNotice.DoesNotExist: @@ -48,7 +48,7 @@ class Command(BaseCommand): 'fellchensammlung.rescue_org' ) - adoption1 = baker.make(AdoptionNotice, name="Vermittung1TestSalt9227", organization=rescue1) + adoption1 = baker.make(AdoptionNotice, name="Vermittlung1TestSalt9227", organization=rescue1) adoption2 = baker.make(AdoptionNotice, name="Vermittung2", organization=rescue2) diff --git a/src/fellchensammlung/migrations/0001_initial.py b/src/fellchensammlung/migrations/0001_initial.py index 390b840..e166f24 100644 --- a/src/fellchensammlung/migrations/0001_initial.py +++ b/src/fellchensammlung/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.0.3 on 2024-04-14 13:57 +# Generated by Django 5.0.6 on 2024-06-06 16:11 import datetime import django.contrib.auth.models @@ -19,6 +19,87 @@ class Migration(migrations.Migration): ] operations = [ + migrations.CreateModel( + name="AdoptionNotice", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "created_at", + models.DateField( + default=datetime.datetime.now, verbose_name="Erstellt am" + ), + ), + ( + "searching_since", + models.DateField(verbose_name="Sucht nach einem Zuhause seit"), + ), + ("name", models.CharField(max_length=200)), + ( + "description", + models.TextField( + blank=True, null=True, verbose_name="Beschreibung" + ), + ), + ( + "further_information", + models.URLField( + blank=True, null=True, verbose_name="Link zu mehr Informationen" + ), + ), + ( + "group_only", + models.BooleanField( + default=False, verbose_name="Ausschließlich Gruppenadoption" + ), + ), + ( + "location_string", + models.CharField(max_length=200, verbose_name="Ortsangabe"), + ), + ], + options={ + "permissions": [ + ( + "create_active_adoption_notice", + "Can create an active adoption notice", + ) + ], + }, + ), + migrations.CreateModel( + name="Text", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("title", models.CharField(max_length=100)), + ("content", models.TextField(verbose_name="Inhalt")), + ( + "text_code", + models.CharField( + blank=True, max_length=24, verbose_name="Text code" + ), + ), + ], + options={ + "verbose_name": "Text", + "verbose_name_plural": "Texte", + }, + ), migrations.CreateModel( name="Image", fields=[ @@ -31,7 +112,6 @@ class Migration(migrations.Migration): verbose_name="ID", ), ), - ("title", models.CharField(max_length=200)), ("image", models.ImageField(upload_to="images")), ("alt_text", models.TextField(max_length=2000)), ], @@ -82,26 +162,42 @@ class Migration(migrations.Migration): verbose_name="ID", ), ), - ("name", models.CharField(max_length=200)), - ("postcode", models.CharField(max_length=200)), + ("place_id", models.IntegerField()), + ("latitude", models.FloatField()), + ("longitude", models.FloatField()), + ("name", models.CharField(max_length=2000)), + ], + ), + migrations.CreateModel( + name="Report", + fields=[ ( - "country", + "id", + models.UUIDField( + default=uuid.uuid4, + help_text="ID dieses reports", + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "status", models.CharField( choices=[ - ("DE", "Germany"), - ("AT", "Austria"), - ("CH", "Switzerland"), + ("action taken", "Action was taken"), + ("no action taken", "No action was taken"), + ("waiting", "Waiting for moderator action"), ], - max_length=20, - ), - ), - ( - "description", - models.TextField( - blank=True, null=True, verbose_name="Beschreibung" + max_length=30, ), ), + ("user_comment", models.TextField(blank=True)), + ("created_at", models.DateTimeField(auto_now_add=True)), ], + options={ + "permissions": [], + }, ), migrations.CreateModel( name="Species", @@ -244,7 +340,7 @@ class Migration(migrations.Migration): ], ), migrations.CreateModel( - name="AdoptionNotice", + name="AdoptionNoticeStatus", fields=[ ( "id", @@ -256,47 +352,119 @@ class Migration(migrations.Migration): ), ), ( - "created_at", - models.DateField( - default=datetime.datetime.now, verbose_name="Erstellt am" + "major_status", + models.CharField( + choices=[ + ("active", "active"), + ("in_review", "in review"), + ("closed", "closed"), + ("disabled", "disabled"), + ], + max_length=200, ), ), ( - "searching_since", - models.DateField(verbose_name="Sucht nach einem Zuhause seit"), - ), - ("name", models.CharField(max_length=200)), - ( - "description", - models.TextField( - blank=True, null=True, verbose_name="Beschreibung" + "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, ), ), ( - "further_information", - models.URLField( - blank=True, null=True, verbose_name="Link zu mehr Informationen" + "adoption_notice", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + to="fellchensammlung.adoptionnotice", ), ), - ( - "group_only", - models.BooleanField( - default=False, verbose_name="Ausschließlich Gruppenadoption" - ), - ), - ( - "photos", - models.ManyToManyField(blank=True, to="fellchensammlung.image"), - ), ], - options={ - "permissions": [ - ( - "create_active_adoption_notice", - "Can create an active adoption notice", - ) - ], - }, + ), + migrations.CreateModel( + name="Announcement", + fields=[ + ( + "text_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="fellchensammlung.text", + ), + ), + ("logged_in_only", models.BooleanField(default=False)), + ("created_at", models.DateTimeField(auto_now_add=True)), + ( + "publish_start_time", + models.DateTimeField(verbose_name="Veröffentlichungszeitpunk"), + ), + ( + "publish_end_time", + models.DateTimeField(verbose_name="Veröffentlichungsende"), + ), + ( + "type", + models.CharField( + choices=[ + ("important", "important"), + ("warning", "warning"), + ("info", "info"), + ], + default="info", + max_length=100, + ), + ), + ], + bases=("fellchensammlung.text",), + ), + migrations.AddField( + model_name="adoptionnotice", + name="photos", + field=models.ManyToManyField(blank=True, to="fellchensammlung.image"), + ), + migrations.AddField( + model_name="text", + name="language", + field=models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="fellchensammlung.language", + verbose_name="Sprache", + ), + ), + migrations.AddField( + model_name="adoptionnotice", + name="location", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="fellchensammlung.location", + ), ), migrations.CreateModel( name="Member", @@ -348,42 +516,46 @@ class Migration(migrations.Migration): }, ), migrations.CreateModel( - name="Report", + name="Comment", fields=[ ( "id", - models.UUIDField( - default=uuid.uuid4, - help_text="ID dieses reports", + models.BigAutoField( + auto_created=True, primary_key=True, serialize=False, verbose_name="ID", ), ), - ( - "status", - models.CharField( - choices=[ - ("action taken", "Action was taken"), - ("no action taken", "No action was taken"), - ("waiting", "Waiting for moderator action"), - ], - max_length=30, - ), - ), - ("comment", models.TextField(blank=True)), ("created_at", models.DateTimeField(auto_now_add=True)), + ("text", models.TextField(verbose_name="Inhalt")), ( "adoption_notice", models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, to="fellchensammlung.adoptionnotice", + verbose_name="AdoptionNotice", + ), + ), + ( + "reply_to", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + to="fellchensammlung.comment", + verbose_name="Antwort auf", + ), + ), + ( + "user", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="fellchensammlung.member", + verbose_name="Nutzer*in", ), ), ], - options={ - "permissions": [], - }, ), migrations.CreateModel( name="ModerationAction", @@ -439,6 +611,12 @@ class Migration(migrations.Migration): "trusted", models.BooleanField(default=False, verbose_name="Vertrauenswürdig"), ), + ( + "location_string", + models.CharField( + max_length=200, verbose_name="Ort der Organisation" + ), + ), ( "instagram", models.URLField( @@ -508,7 +686,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name="report", name="reported_broken_rules", - field=models.ManyToManyField(blank=True, to="fellchensammlung.rule"), + field=models.ManyToManyField(to="fellchensammlung.rule"), ), migrations.CreateModel( name="Animal", @@ -563,37 +741,51 @@ class Migration(migrations.Migration): ], ), migrations.CreateModel( - name="Text", + name="ReportAdoptionNotice", fields=[ ( - "id", - models.BigAutoField( + "report_ptr", + models.OneToOneField( auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, primary_key=True, serialize=False, - verbose_name="ID", - ), - ), - ("title", models.CharField(max_length=100)), - ("content", models.TextField(verbose_name="Inhalt")), - ( - "text_code", - models.CharField( - blank=True, max_length=24, verbose_name="Text code" + to="fellchensammlung.report", ), ), ( - "language", + "adoption_notice", models.ForeignKey( - on_delete=django.db.models.deletion.PROTECT, - to="fellchensammlung.language", - verbose_name="Sprache", + on_delete=django.db.models.deletion.CASCADE, + to="fellchensammlung.adoptionnotice", ), ), ], - options={ - "verbose_name": "Text", - "verbose_name_plural": "Texte", - }, + bases=("fellchensammlung.report",), + ), + migrations.CreateModel( + name="ReportComment", + fields=[ + ( + "report_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="fellchensammlung.report", + ), + ), + ( + "reported_comment", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="fellchensammlung.comment", + ), + ), + ], + bases=("fellchensammlung.report",), ), ] diff --git a/src/fellchensammlung/migrations/0002_comment.py b/src/fellchensammlung/migrations/0002_comment.py deleted file mode 100644 index dd6f3d0..0000000 --- a/src/fellchensammlung/migrations/0002_comment.py +++ /dev/null @@ -1,56 +0,0 @@ -# Generated by Django 5.0.6 on 2024-06-03 19:22 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("fellchensammlung", "0001_initial"), - ] - - operations = [ - migrations.CreateModel( - name="Comment", - fields=[ - ( - "id", - models.BigAutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("created_at", models.DateTimeField(auto_now_add=True)), - ("text", models.TextField(verbose_name="Inhalt")), - ( - "adoption_notice", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - to="fellchensammlung.adoptionnotice", - verbose_name="AdoptionNotice", - ), - ), - ( - "reply_to", - models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.CASCADE, - to="fellchensammlung.comment", - verbose_name="Antwort auf", - ), - ), - ( - "user", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - to="fellchensammlung.member", - verbose_name="Nutzer*in", - ), - ), - ], - ), - ] diff --git a/src/fellchensammlung/migrations/0003_remove_report_adoption_notice_and_more.py b/src/fellchensammlung/migrations/0003_remove_report_adoption_notice_and_more.py deleted file mode 100644 index 2c3c23a..0000000 --- a/src/fellchensammlung/migrations/0003_remove_report_adoption_notice_and_more.py +++ /dev/null @@ -1,71 +0,0 @@ -# Generated by Django 5.0.6 on 2024-06-04 06:22 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("fellchensammlung", "0002_comment"), - ] - - operations = [ - migrations.RemoveField( - model_name="report", - name="adoption_notice", - ), - migrations.RenameField( - model_name="report", - old_name="comment", - new_name="user_comment", - ), - migrations.CreateModel( - name="ReportComment", - fields=[ - ( - "report_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - primary_key=True, - serialize=False, - to="fellchensammlung.report", - ), - ), - ( - "reported_comment", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - to="fellchensammlung.comment", - ), - ), - ], - bases=("fellchensammlung.report",), - ), - migrations.CreateModel( - name="ReportAdoptionNotice", - fields=[ - ( - "report_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - primary_key=True, - serialize=False, - to="fellchensammlung.report", - ), - ), - ( - "adoption_notice", - models.ForeignKey( - on_delete=django.db.models.deletion.CASCADE, - to="fellchensammlung.adoptionnotice", - ), - ), - ], - bases=("fellchensammlung.report",), - ), - ] diff --git a/src/fellchensammlung/migrations/0004_alter_report_reported_broken_rules.py b/src/fellchensammlung/migrations/0004_alter_report_reported_broken_rules.py deleted file mode 100644 index f4406fa..0000000 --- a/src/fellchensammlung/migrations/0004_alter_report_reported_broken_rules.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 5.0.6 on 2024-06-04 08:40 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("fellchensammlung", "0003_remove_report_adoption_notice_and_more"), - ] - - operations = [ - migrations.AlterField( - model_name="report", - name="reported_broken_rules", - field=models.ManyToManyField(to="fellchensammlung.rule"), - ), - ] diff --git a/src/fellchensammlung/migrations/0005_announcement.py b/src/fellchensammlung/migrations/0005_announcement.py deleted file mode 100644 index 55282da..0000000 --- a/src/fellchensammlung/migrations/0005_announcement.py +++ /dev/null @@ -1,41 +0,0 @@ -# Generated by Django 5.0.6 on 2024-06-05 04:21 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("fellchensammlung", "0004_alter_report_reported_broken_rules"), - ] - - operations = [ - migrations.CreateModel( - name="Announcement", - fields=[ - ( - "text_ptr", - models.OneToOneField( - auto_created=True, - on_delete=django.db.models.deletion.CASCADE, - parent_link=True, - primary_key=True, - serialize=False, - to="fellchensammlung.text", - ), - ), - ("logged_in_only", models.BooleanField(default=False)), - ("created_at", models.DateTimeField(auto_now_add=True)), - ( - "publish_start_time", - models.DateTimeField(verbose_name="Veröffentlichungszeitpunk"), - ), - ( - "publish_end_time", - models.DateTimeField(verbose_name="Veröffentlichungsende"), - ), - ], - bases=("fellchensammlung.text",), - ), - ] diff --git a/src/fellchensammlung/migrations/0006_announcement_type.py b/src/fellchensammlung/migrations/0006_announcement_type.py deleted file mode 100644 index 3c08a15..0000000 --- a/src/fellchensammlung/migrations/0006_announcement_type.py +++ /dev/null @@ -1,26 +0,0 @@ -# Generated by Django 5.0.6 on 2024-06-05 06:21 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("fellchensammlung", "0005_announcement"), - ] - - operations = [ - migrations.AddField( - model_name="announcement", - name="type", - field=models.CharField( - choices=[ - ("important", "important"), - ("warning", "warning"), - ("info", "info"), - ], - default="info", - max_length=100, - ), - ), - ] diff --git a/src/fellchensammlung/migrations/0007_remove_location_country_remove_location_description_and_more.py b/src/fellchensammlung/migrations/0007_remove_location_country_remove_location_description_and_more.py deleted file mode 100644 index 891e891..0000000 --- a/src/fellchensammlung/migrations/0007_remove_location_country_remove_location_description_and_more.py +++ /dev/null @@ -1,81 +0,0 @@ -# Generated by Django 5.0.6 on 2024-06-05 13:19 - -import django.db.models.deletion -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ("fellchensammlung", "0006_announcement_type"), - ] - - operations = [ - migrations.RemoveField( - model_name="location", - name="country", - ), - migrations.RemoveField( - model_name="location", - name="description", - ), - migrations.RemoveField( - model_name="location", - name="postcode", - ), - migrations.AddField( - model_name="adoptionnotice", - name="location", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - to="fellchensammlung.location", - ), - ), - migrations.AddField( - model_name="adoptionnotice", - name="location_string", - field=models.CharField( - default="72072", max_length=200, verbose_name="Ortsangabe" - ), - preserve_default=False, - ), - migrations.AddField( - model_name="location", - name="latitude", - field=models.FloatField(default=47), - preserve_default=False, - ), - migrations.AddField( - model_name="location", - name="longitude", - field=models.FloatField(default=9), - preserve_default=False, - ), - migrations.AddField( - model_name="location", - name="osm_id", - field=models.IntegerField(default=1), - preserve_default=False, - ), - migrations.AddField( - model_name="location", - name="place_id", - field=models.IntegerField(default=1), - preserve_default=False, - ), - migrations.AddField( - model_name="rescueorganization", - name="location_string", - field=models.CharField( - default="72072", max_length=200, verbose_name="Ort der Organisation" - ), - preserve_default=False, - ), - migrations.AlterField( - model_name="location", - name="name", - field=models.CharField(max_length=2000), - ), - ] diff --git a/src/fellchensammlung/migrations/0008_remove_location_osm_id.py b/src/fellchensammlung/migrations/0008_remove_location_osm_id.py deleted file mode 100644 index 72b1cf0..0000000 --- a/src/fellchensammlung/migrations/0008_remove_location_osm_id.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 5.0.6 on 2024-06-05 19:52 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ( - "fellchensammlung", - "0007_remove_location_country_remove_location_description_and_more", - ), - ] - - operations = [ - migrations.RemoveField( - model_name="location", - name="osm_id", - ), - ] diff --git a/src/fellchensammlung/migrations/0009_remove_image_title.py b/src/fellchensammlung/migrations/0009_remove_image_title.py deleted file mode 100644 index 84c9b03..0000000 --- a/src/fellchensammlung/migrations/0009_remove_image_title.py +++ /dev/null @@ -1,17 +0,0 @@ -# Generated by Django 5.0.6 on 2024-06-06 08:48 - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ("fellchensammlung", "0008_remove_location_osm_id"), - ] - - operations = [ - migrations.RemoveField( - model_name="image", - name="title", - ), - ] diff --git a/src/fellchensammlung/migrations/0010_status.py b/src/fellchensammlung/migrations/0010_status.py deleted file mode 100644 index 6d69e8f..0000000 --- a/src/fellchensammlung/migrations/0010_status.py +++ /dev/null @@ -1,70 +0,0 @@ -# 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 deleted file mode 100644 index 14613e3..0000000 --- a/src/fellchensammlung/migrations/0011_adoptionnotice_status.py +++ /dev/null @@ -1,27 +0,0 @@ -# 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 98b101d..7fe80c9 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -35,64 +35,6 @@ 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) @@ -182,7 +124,6 @@ class AdoptionNotice(models.Model): 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, ) - status = models.ForeignKey(Status, on_delete=models.PROTECT) @property def animals(self): @@ -258,7 +199,69 @@ class AdoptionNotice(models.Model): @property def is_active(self): - return self.status.is_active + if not hasattr(self, 'adoptionnoticestatus'): + return False + return self.adoptionnoticestatus.is_active + + +class AdoptionNoticeStatus(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", + "technical_error": "technical_error", + "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) + adoption_notice = models.OneToOneField(AdoptionNotice, on_delete=models.CASCADE) + + def __str__(self): + return f"{self.adoption_notice}: {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 AdoptionNoticeStatus.MINOR_STATUS_CHOICES[major_status] class Animal(models.Model):