Commit 02fc622f authored by Ron Rodillas's avatar Ron Rodillas

Created the book and author edit detail pages

parent fb4b63f6
...@@ -18,6 +18,9 @@ class Author(models.Model): ...@@ -18,6 +18,9 @@ class Author(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('bookshelf:AuthorDetailView', kwargs={'pk': self.pk}) return reverse('bookshelf:AuthorDetailView', kwargs={'pk': self.pk})
def get_update_url(self):
return reverse('bookshelf:AuthorUpdateView', kwargs={'pk': self.pk})
class Books(models.Model): class Books(models.Model):
title = models.CharField(max_length=100) title = models.CharField(max_length=100)
author = models.ForeignKey(Author, on_delete=models.CASCADE) author = models.ForeignKey(Author, on_delete=models.CASCADE)
...@@ -33,4 +36,7 @@ class Books(models.Model): ...@@ -33,4 +36,7 @@ class Books(models.Model):
return self.__str__() return self.__str__()
def get_absolute_url(self): def get_absolute_url(self):
return reverse('bookshelf:BookDetailView', kwargs={'pk': self.pk}) return reverse('bookshelf:BookDetailView', kwargs={'pk': self.pk})
\ No newline at end of file
def get_update_url(self):
return reverse('bookshelf:BookUpdateView', kwargs={'pk': self.pk})
\ No newline at end of file
...@@ -20,7 +20,9 @@ p1 { ...@@ -20,7 +20,9 @@ p1 {
{{object.age}}<br> {{object.age}}<br>
{{object.nationality}}<br> {{object.nationality}}<br>
</p1> </p1>
{{object.bio}}<br> {{object.bio}}<br><br>
<a href="{{object.get_update_url}}"><button> Edit Author </button></a><br>
<br><br>
<h2>Books by {{object.get_name}} I love:</h2> <h2>Books by {{object.get_name}} I love:</h2>
<p2></p2> <p2></p2>
<div> <div>
......
...@@ -26,6 +26,8 @@ p1 { ...@@ -26,6 +26,8 @@ p1 {
<br> <br>
<div> <div>
<a href="{{object.get_update_url}}"><button> Edit Book </button></a><br>
<br><br>
<a href="{% url 'bookshelf:home' %}"> Home</a> <a href="{% url 'bookshelf:home' %}"> Home</a>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
<a href="{% url 'bookshelf:BooksView' %}"> Books</a> <a href="{% url 'bookshelf:BooksView' %}"> Books</a>
......
{% extends 'base.html' %}
{% load static %}
{% block title %}
Add New Book
{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}
Add New Book
{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
\ No newline at end of file
...@@ -9,6 +9,8 @@ urlpatterns = [ ...@@ -9,6 +9,8 @@ urlpatterns = [
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='AuthorDetailView'), path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='AuthorDetailView'),
path ('books/add', BooksCreateView.as_view(), name='AddBook'), path ('books/add', BooksCreateView.as_view(), name='AddBook'),
path ('authors/add/', AuthorCreateView.as_view(), name='AddAuthor'), path ('authors/add/', AuthorCreateView.as_view(), name='AddAuthor'),
path('books/<int:pk>/edit', BookUpdateView.as_view(), name='BookUpdateView'),
path('authors/<int:pk>/edit', AuthorUpdateView.as_view(), name='AuthorUpdateView'),
] ]
app_name="bookshelf" app_name="bookshelf"
\ No newline at end of file
...@@ -33,4 +33,14 @@ class BooksCreateView(CreateView): ...@@ -33,4 +33,14 @@ class BooksCreateView(CreateView):
class AuthorCreateView(CreateView): class AuthorCreateView(CreateView):
model = Author model = Author
fields = '__all__' fields = '__all__'
template_name = 'bookshelf/add-author.html' template_name = 'bookshelf/add-author.html'
\ No newline at end of file
class BookUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-book.html'
class AuthorUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/edit-author.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