Commit b9e8b471 authored by Jan Ericsson Ong Ang's avatar Jan Ericsson Ong Ang

fixed author and book for loops

parent 407bc54d
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
{% block content %} {% block content %}
{% block header %}<h1>{{ nickname }}'s Favorite Authors:</h1>{% endblock %} {% block header %}<h1>{{ nickname }}'s Favorite Authors:</h1>{% endblock %}
<br> <br>
{% for author in authors %} {% for author in author_data %}
<a href="/bookshelf/authors/{{ author.pk }}/details/">{{ author.first_name }} {{ author.last_name }}</a> <a href="/bookshelf/authors/{{ author.pk }}/details/">{{ author.first_name }} {{ author.last_name }}</a>
<br>
{% endfor %} {% endfor %}
<br> <br>
......
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
{% block content %} {% block content %}
{% block header %}<h1>{{ nickname }}'s Favorite Books:</h1>{% endblock %} {% block header %}<h1>{{ nickname }}'s Favorite Books:</h1>{% endblock %}
<br> <br>
{% for book in books %} {% for book in book_data %}
<a href="/bookshelf/books/{{ book.pk }}/details/"><p>{{ book.title }}</p></a> <a href="/bookshelf/books/{{ book.pk }}/details/">{{ book.title }}</a>
<br>
{% endfor %} {% endfor %}
<br> <br>
......
...@@ -12,18 +12,22 @@ def HomeView(request): ...@@ -12,18 +12,22 @@ def HomeView(request):
class AuthorView(ListView): class AuthorView(ListView):
def get(self, request): def get(self, request):
model = Author model = Author
return render(request, 'bookshelf/authors.html', {'nickname': 'Jan'}) author_data = Author.objects.all().values()
return render(request, 'bookshelf/authors.html', {'nickname': 'Jan', 'author_data': author_data})
class AuthorDetailView(DetailView): class AuthorDetailView(DetailView):
model = Author model = Author
model_data = Author
template_name = 'bookshelf/author_details.html' template_name = 'bookshelf/author_details.html'
class BooksView(ListView): class BooksView(ListView):
def get(self, request): def get(self, request):
model = Books model = Books
return render(request, 'bookshelf/books.html', {'nickname': 'Jan'}) book_data = Books.objects.all().values()
return render(request, 'bookshelf/books.html', {'nickname': 'Jan', 'book_data': book_data})
class BookDetailView(DetailView): class BookDetailView(DetailView):
model = Books model = Books
model_data = Books
template_name = 'bookshelf/books_details.html' template_name = 'bookshelf/books_details.html'
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment