feat: Add animal cards to adoption notice detail

This commit is contained in:
moanos [he/him] 2024-05-30 15:49:32 +02:00
parent 273bef9526
commit dabdc0ab34
4 changed files with 42 additions and 2 deletions

View File

@ -41,6 +41,19 @@ class AdoptionNoticeForm(forms.ModelForm):
fields = ['name', "group_only", "further_information", "description", "searching_since"] fields = ['name', "group_only", "further_information", "description", "searching_since"]
class AnimalForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_class = 'form-animal'
self.helper.add_input(Submit('save-and-add-another-animal', _('Speichern und weiteres Tier hinzufügen')))
self.helper.add_input(Submit('save-and-finish', _('Speichern und beenden')))
class Meta:
model = Animal
fields = ["name", "date_of_birth", "species", "sex", "description"]
class ImageForm(forms.ModelForm): class ImageForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)

View File

@ -5,7 +5,8 @@
{% block content %} {% block content %}
<div class="detail-adoption-notice-header"> <div class="detail-adoption-notice-header">
<h1 class="detail-adoption-notice-header">{{ adoption_notice.name }}</h1> <h1 class="detail-adoption-notice-header">{{ adoption_notice.name }}</h1>
<a class="btn2 detail-adoption-notice-header" href="{% url 'adoption-notice-edit' 1 %}/{{ adoption_notice.pk }}">{% translate 'Bearbeiten' %}</a> <a class="btn2 detail-adoption-notice-header"
href="{% url 'adoption-notice-edit' 1 %}/{{ adoption_notice.pk }}">{% translate 'Bearbeiten' %}</a>
</div> </div>
<div class="table-adoption-notice-info"> <div class="table-adoption-notice-info">
<table> <table>
@ -37,6 +38,13 @@
{% endif %} {% endif %}
</p> </p>
<div>
{% for animal in adoption_notice.animals %}
{% include "fellchensammlung/partials/partial-animal-card.html" %}
{% endfor %}
</div>
{% include "fellchensammlung/partials/partial-comment-section.html" %} {% include "fellchensammlung/partials/partial-comment-section.html" %}
{% endblock %} {% endblock %}

View File

@ -17,6 +17,8 @@ urlpatterns = [
path("vermittlung/<int:adoption_notice_id>/", views.adoption_notice_detail, name="adoption-notice-detail"), path("vermittlung/<int:adoption_notice_id>/", views.adoption_notice_detail, name="adoption-notice-detail"),
# ex: /adoption_notice/7/edit # ex: /adoption_notice/7/edit
path("vermittlung/<int:adoption_notice_id>/edit", views.adoption_notice_edit, name="adoption-notice-edit"), path("vermittlung/<int:adoption_notice_id>/edit", views.adoption_notice_edit, name="adoption-notice-edit"),
# ex: /adoption_notice/2/add-animal
path("vermittlung/<int:adoption_notice_id>/add-animal", views.adoption_notice_add_animal, name="adoption-notice-add-animal"),
# ex: /search/ # ex: /search/
path("suchen/", views.search, name="search"), path("suchen/", views.search, name="search"),

View File

@ -13,7 +13,7 @@ from notfellchen import settings
from fellchensammlung import logger from fellchensammlung import logger
from fellchensammlung.models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \ from fellchensammlung.models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \
Member Member
from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, CommentForm, ReportCommentForm from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, CommentForm, ReportCommentForm, AnimalForm
from .models import Language from .models import Language
@ -101,6 +101,23 @@ def add_adoption(request):
form = AdoptionNoticeForm() form = AdoptionNoticeForm()
return render(request, 'fellchensammlung/forms/form_add_adoption.html', {'form': form}) return render(request, 'fellchensammlung/forms/form_add_adoption.html', {'form': form})
@login_required
def adoption_notice_add_animal(request, adoption_notice_id):
if request.method == 'POST':
form = AnimalForm(request.POST, request.FILES)
if form.is_valid():
instance = form.save(commit=False)
instance.adoption_notice_id = adoption_notice_id
instance.save()
form.save_m2m()
if True:
return redirect(reverse("adoption-notice-detail", args=[instance.pk]))
else:
return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html')
else:
form = AnimalForm()
return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html', {'form': form})
@login_required @login_required
def edit_adoption_notice(request, animal_id): def edit_adoption_notice(request, animal_id):