Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. class Author(models.Model):
  2. first_name = models.CharField(max_length=255)
  3. last_name = models.CharField(max_length=255)
  4.  
  5. class Book(models.Model):
  6. title = models.CharField(max_length=255)
  7. author = models.ForeignKey(Author)
  8.  
  9.  
  10. def view(request):
  11. return render(request, 'books.html', {'books': Books.objects.all()})
  12.  
  13.  
  14. <html>
  15. <head></head>
  16. <body>
  17. <h2>Books</h2>
  18. <ul>
  19. {% for book in books %}
  20. <li>&laquo;{{ book.title }}&raquo; by {{ book.author.first_name }} {{ book.author.last_name }}</li>
  21. {% endfor %}
  22. </ul>
  23. </body>
  24. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement