Hi Stackoverflow people, You will help with the following.
My urls:
path('Autorow/szczegoły/<int:id>/', views.Szczegoly_autorzy, name='Szczegoly_autorzy'),
My views:
def Szczegoly_autorzy(request, id):
autor = get_object_or_404(Author, pk=id)
return render(request, 'Szczegoly_autorzy.html', {'autor': autor})
My models:
class Author(models.Model):
zdjecie_autora = models.ImageField(null=False, blank=True, upload_to='zdjecia_autorow')
imie_nazwisko = models.CharField(max_length=100, unique=True)
data_urodzenia = models.DateField(null=True, blank=True)
informacje = models.TextField()
def __str__(self):
return self.imie_nazwisko
class Book(models.Model):
tytul = models.CharField(max_length=60, unique=True)
autor = models.ForeignKey(Author, on_delete=models.CASCADE)
opis = models.TextField(null=True, blank=True)
rok_wydania = models.DateField(null=True, blank=True)
zdjecie = models.ImageField(null=False, blank=True, upload_to='zdjecia_ksiazek')
def __str__(self):
return self.tytul
Templates:
{% for ksiazki in autor.ksiazki_set.all %}
<li><a href="{% url 'Szczegoly_ksiazki' ksiazki.id %}">"{{ ksiazki }}"</a></li>
{% endfor %}
I don't see the list of books the author wrote in my templates. This is my second app and it works in the first one, but I don't know where I'm making a mistake here. Help me