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):
def get_absolute_url(self):
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):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author, on_delete=models.CASCADE)
......@@ -33,4 +36,7 @@ class Books(models.Model):
return self.__str__()
def get_absolute_url(self):
return reverse('bookshelf:BookDetailView', kwargs={'pk': self.pk})
\ No newline at end of file
return reverse('bookshelf:BookDetailView', kwargs={'pk': self.pk})
def get_update_url(self):
return reverse('bookshelf:BookUpdateView', kwargs={'pk': self.pk})
\ No newline at end of file
......@@ -20,7 +20,9 @@ p1 {
{{object.age}}<br>
{{object.nationality}}<br>
</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>
<p2></p2>
<div>
......
......@@ -26,6 +26,8 @@ p1 {
<br>
<div>
<a href="{{object.get_update_url}}"><button> Edit Book </button></a><br>
<br><br>
<a href="{% url 'bookshelf:home' %}"> Home</a>
&nbsp;&nbsp;&nbsp;
<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 = [
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='AuthorDetailView'),
path ('books/add', BooksCreateView.as_view(), name='AddBook'),
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"
\ No newline at end of file
......@@ -33,4 +33,14 @@ class BooksCreateView(CreateView):
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
\ No newline at end of file
template_name = 'bookshelf/add-author.html'
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