feat: Add basic list o adoption notices
This commit is contained in:
		@@ -1,4 +1,5 @@
 | 
				
			|||||||
from django.db import models
 | 
					from django.db import models
 | 
				
			||||||
 | 
					from django.urls import reverse
 | 
				
			||||||
from django.contrib.auth.models import User
 | 
					from django.contrib.auth.models import User
 | 
				
			||||||
from django.utils.translation import gettext_lazy as _
 | 
					from django.utils.translation import gettext_lazy as _
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -63,6 +64,10 @@ class Animal(models.Model):
 | 
				
			|||||||
    def __str__(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        return f"{self.name}"
 | 
					        return f"{self.name}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_absolute_url(self):
 | 
				
			||||||
 | 
					        """Returns the url to access a detailed page for the animal."""
 | 
				
			||||||
 | 
					        return reverse('animal-detail', args=[str(self.id)])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    date_of_birth = models.DateField(null=True, blank=True, verbose_name=_('Date of birth'))
 | 
					    date_of_birth = models.DateField(null=True, blank=True, verbose_name=_('Date of birth'))
 | 
				
			||||||
    name = models.CharField(max_length=200)
 | 
					    name = models.CharField(max_length=200)
 | 
				
			||||||
    description = models.TextField(null=True, blank=True, verbose_name=_('Description'))
 | 
					    description = models.TextField(null=True, blank=True, verbose_name=_('Description'))
 | 
				
			||||||
@@ -85,6 +90,10 @@ class AdoptionNotice(models.Model):
 | 
				
			|||||||
    animals = models.ManyToManyField(Animal)
 | 
					    animals = models.ManyToManyField(Animal)
 | 
				
			||||||
    photos = models.ManyToManyField(Image, blank=True)
 | 
					    photos = models.ManyToManyField(Image, blank=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @property
 | 
				
			||||||
 | 
					    def animals_list(self):
 | 
				
			||||||
 | 
					        return self.animals.all()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MarkdownContent(models.Model):
 | 
					class MarkdownContent(models.Model):
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					{% load custom_tags %}
 | 
				
			||||||
 | 
					<ul>
 | 
				
			||||||
 | 
					    {% for adoption_notice in adoption_notices %}
 | 
				
			||||||
 | 
					        <li>
 | 
				
			||||||
 | 
					            <div>
 | 
				
			||||||
 | 
					                <h1>{{ adoption_notice.name }}</h1>
 | 
				
			||||||
 | 
					                <p><b>Notfellchen:</b>  {{ adoption_notice.animals.all|join_link:", " | safe }}
 | 
				
			||||||
 | 
					                <ul>
 | 
				
			||||||
 | 
					                    {% for animal in adoption_notice.animal_list %}
 | 
				
			||||||
 | 
					                        <li>{{ animal.name }}</li>
 | 
				
			||||||
 | 
					                    {% endfor %}
 | 
				
			||||||
 | 
					                </ul>
 | 
				
			||||||
 | 
					                </p>
 | 
				
			||||||
 | 
					                <p>{{ adoption_notice.description }}</p>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					        </li>
 | 
				
			||||||
 | 
					    {% endfor %}
 | 
				
			||||||
 | 
					</ul>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -3,4 +3,5 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
{% block content %}
 | 
					{% block content %}
 | 
				
			||||||
  Suche...
 | 
					  Suche...
 | 
				
			||||||
 | 
					    {% include "fellchensammlung/list-adoption-notices.html" %}
 | 
				
			||||||
{% endblock %}
 | 
					{% endblock %}
 | 
				
			||||||
							
								
								
									
										0
									
								
								src/fellchensammlung/templatetags/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/fellchensammlung/templatetags/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										29
									
								
								src/fellchensammlung/templatetags/custom_tags.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/fellchensammlung/templatetags/custom_tags.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					from django import template
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					register = template.Library()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@register.filter('join_link')
 | 
				
			||||||
 | 
					def join_link(value, arg):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    Joins the items of value as link to itself together using arg
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    The item in values are properly escaped so the safe filter can be applied
 | 
				
			||||||
 | 
					    Example usage:
 | 
				
			||||||
 | 
					    {%  book.author.all|join_link:", " % | safe}
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    from django.utils.html import conditional_escape
 | 
				
			||||||
 | 
					    arr = []
 | 
				
			||||||
 | 
					    for i in value:
 | 
				
			||||||
 | 
					        arr.append('<a href="%s">%s</a>' % (
 | 
				
			||||||
 | 
					            i.get_absolute_url(), conditional_escape(i)
 | 
				
			||||||
 | 
					        ))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return arg.join(arr)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@register.filter
 | 
				
			||||||
 | 
					def get_type(value):
 | 
				
			||||||
 | 
					    return type(value)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -22,7 +22,9 @@ def animal_detail(request, animal_id):
 | 
				
			|||||||
    return HttpResponse(response % animal_id)
 | 
					    return HttpResponse(response % animal_id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def search(request):
 | 
					def search(request):
 | 
				
			||||||
    return render(request, 'fellchensammlung/search.html')
 | 
					    latest_adoption_list = AdoptionNotice.objects.order_by("-created_at")[:5]
 | 
				
			||||||
 | 
					    context = {"adoption_notices": latest_adoption_list}
 | 
				
			||||||
 | 
					    return render(request, 'fellchensammlung/search.html', context=context)
 | 
				
			||||||
def add_adoption(request):
 | 
					def add_adoption(request):
 | 
				
			||||||
    return render(request, 'fellchensammlung/add_adoption.html')
 | 
					    return render(request, 'fellchensammlung/add_adoption.html')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user