From a28b6ce4b372c08ed7f4124938d059fbffc9f0aa Mon Sep 17 00:00:00 2001 From: moanos Date: Sun, 29 Sep 2024 23:35:18 +0200 Subject: [PATCH] feat: Add subscriptions to admin site --- src/fellchensammlung/admin.py | 3 ++- src/fellchensammlung/models.py | 3 +++ src/fellchensammlung/templates/fellchensammlung/search.html | 2 +- src/fellchensammlung/views.py | 6 +++--- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/fellchensammlung/admin.py b/src/fellchensammlung/admin.py index 833a196..5c71ec2 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, \ - Comment, Report, Announcement, AdoptionNoticeStatus, User + Comment, Report, Announcement, AdoptionNoticeStatus, User, Subscriptions class StatusInline(admin.StackedInline): @@ -61,3 +61,4 @@ admin.site.register(Language) admin.site.register(Text) admin.site.register(Announcement) admin.site.register(AdoptionNoticeStatus) +admin.site.register(Subscriptions) diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index b5910fc..32f644d 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -597,3 +597,6 @@ class Subscriptions(models.Model): owner = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('Nutzer*in')) adoption_notice = models.ForeignKey(AdoptionNotice, on_delete=models.CASCADE, verbose_name=_('AdoptionNotice')) created_at = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return f"{self.owner} - { self.adoption_notice }" diff --git a/src/fellchensammlung/templates/fellchensammlung/search.html b/src/fellchensammlung/templates/fellchensammlung/search.html index 216e703..fba5eb7 100644 --- a/src/fellchensammlung/templates/fellchensammlung/search.html +++ b/src/fellchensammlung/templates/fellchensammlung/search.html @@ -8,7 +8,7 @@ {{ search_form.as_p }} - {% if not place_found %} + {% if place_not_found %}

{% translate "Ort nicht gefunden" %}

{% endif %} {% include "fellchensammlung/lists/list-adoption-notices.html" %} diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index 4d9f28c..077dd6a 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -138,6 +138,7 @@ def animal_detail(request, animal_id): def search(request): + place_not_found = None if request.method == 'POST': latest_adoption_list = AdoptionNotice.objects.order_by("-created_at") active_adoptions = [adoption for adoption in latest_adoption_list if adoption.is_active] @@ -149,13 +150,12 @@ def search(request): geo_api = GeoAPI() search_position = geo_api.get_coordinates_from_query(request.POST['postcode']) if search_position is None: - place_found = False + place_not_found = True adoption_notices_in_distance = active_adoptions else: - place_found = True adoption_notices_in_distance = [a for a in active_adoptions if a.in_distance(search_position, max_distance)] - context = {"adoption_notices": adoption_notices_in_distance, "search_form": search_form, "place_found": place_found} + context = {"adoption_notices": adoption_notices_in_distance, "search_form": search_form, "place_not_found": place_not_found} else: latest_adoption_list = AdoptionNotice.objects.order_by("-created_at") active_adoptions = [adoption for adoption in latest_adoption_list if adoption.is_active]