feat: Add animal cards to adoption notice detail
This commit is contained in:
		@@ -41,6 +41,19 @@ class AdoptionNoticeForm(forms.ModelForm):
 | 
			
		||||
        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):
 | 
			
		||||
    def __init__(self, *args, **kwargs):
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,8 @@
 | 
			
		||||
{% block content %}
 | 
			
		||||
    <div class="detail-adoption-notice-header">
 | 
			
		||||
        <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 class="table-adoption-notice-info">
 | 
			
		||||
        <table>
 | 
			
		||||
@@ -37,6 +38,13 @@
 | 
			
		||||
        {% endif %}
 | 
			
		||||
    </p>
 | 
			
		||||
 | 
			
		||||
    <div>
 | 
			
		||||
        {% for animal in adoption_notice.animals %}
 | 
			
		||||
            {% include "fellchensammlung/partials/partial-animal-card.html" %}
 | 
			
		||||
 | 
			
		||||
        {% endfor %}
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    {% include "fellchensammlung/partials/partial-comment-section.html" %}
 | 
			
		||||
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 
 | 
			
		||||
@@ -17,6 +17,8 @@ urlpatterns = [
 | 
			
		||||
    path("vermittlung/<int:adoption_notice_id>/", views.adoption_notice_detail, name="adoption-notice-detail"),
 | 
			
		||||
    # ex: /adoption_notice/7/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/
 | 
			
		||||
    path("suchen/", views.search, name="search"),
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ from notfellchen import settings
 | 
			
		||||
from fellchensammlung import logger
 | 
			
		||||
from fellchensammlung.models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \
 | 
			
		||||
    Member
 | 
			
		||||
from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, CommentForm, ReportCommentForm
 | 
			
		||||
from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, CommentForm, ReportCommentForm, AnimalForm
 | 
			
		||||
from .models import Language
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -101,6 +101,23 @@ def add_adoption(request):
 | 
			
		||||
        form = AdoptionNoticeForm()
 | 
			
		||||
    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
 | 
			
		||||
def edit_adoption_notice(request, animal_id):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user