{% load sorl_thumbnail %}
<div class="row">
{% for amphibian in amphibians %}
<div class="col-sm-6 col-xl-3">
<div class="card overflow-hidden rounded-2">
<div class="position-relative">
<a href="{% url 'card:amphibian-detail' amphibian.slug %}"
title="TerrarioPedia - Amphibiens - Fiche d'élevage {{ amphibian.get_scientific_name }}">
{% thumbnail amphibian.image "335x235" crop="center" as im %}
{{ im.height }}
{% endthumbnail %}</a>
</div>
<div class="card-body pt-3 p-4">
<h6 class="fw-semibold fs-4">{{ amphibian.get_scientific_name }}</h6>
</div>
</div>
</div>
{% endfor %}
</div>```
#Django-unicorn + sorl_thumbnail work on a models but not on anothers
1 messages · Page 1 of 1 (latest)
There is my functions "*-list.py" :
class AmphibianListView(UnicornView):
show_quantity = 0
snakes = Amphibian.objects.none()
def __init__(self, *args, **kwargs):
super().__init__(**kwargs)
self.show_quantity = kwargs.get("quantity")
self.load(self.show_quantity)
def load(self, quantity):
if self.show_quantity != 0:
self.snakes = Amphibian.objects.order_by('genus', 'species')[:quantity]
else:
self.snakes = Amphibian.objects.order_by('genus', 'species')
from django_unicorn.components import UnicornView
from card.models import Snake
class SnakeListView(UnicornView):
show_quantity = 0
snakes = Snake.objects.none()
def __init__(self, *args, **kwargs):
super().__init__(**kwargs)
self.show_quantity = kwargs.get("quantity")
self.load(self.show_quantity)
def load(self, quantity):
if self.show_quantity != 0:
self.snakes = Snake.objects.order_by('genus', 'species')[:quantity]
else:
self.snakes = Snake.objects.order_by('genus', 'species')
The code {{ im.width }} and {{ im.height }} in amphibians doesn't work ('NoneType' object is not subscriptable) but in snake he's fine.
It's because im is None.