Commit 56720e64 authored by Alvin Joshua Andrada's avatar Alvin Joshua Andrada

fixed urls

parent 95bf4d51
...@@ -7,3 +7,9 @@ class BookForm(forms.ModelForm): ...@@ -7,3 +7,9 @@ class BookForm(forms.ModelForm):
class Meta: class Meta:
model = Book model = Book
fields = ['title', 'author', 'publisher','year_published','ISBN','blurb'] fields = ['title', 'author', 'publisher','year_published','ISBN','blurb']
class AuthorForm(forms.ModelForm):
class Meta:
model = Author
fields = ['first_name', 'last_name', 'age','nationality','bio']
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</ul> </ul>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<form action="/authors" method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form }} {{ form }}
<input type="submit" value="Add Author"> <input type="submit" value="Add Author">
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</ul> </ul>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<form action="/books" method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form }} {{ form }}
<input type="submit" value="Add Book"> <input type="submit" value="Add Book">
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
<h4>{{ author.age }}</h4> <h4>{{ author.age }}</h4>
<h4>{{ author.nationality }}</h4> <h4>{{ author.nationality }}</h4>
<h4>{{ author.bio }}</h4> <h4>{{ author.bio }}</h4>
<button href="{% url 'bookshelf:edit-author' object.id %}">Edit Author</button> <br>
<h4>Books by {{ author.first_name }} {{ author.last_name }} I love:</h4> <h4>Books by {{ author.first_name }} {{ author.last_name }} I love:</h4>
<ul> <ul>
{% for book in books_list %} {% for book in books_list %}
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<h3>{{ object.year_published }}</h3> <h3>{{ object.year_published }}</h3>
<h3>{{ object.ISBN }}</h3> <h3>{{ object.ISBN }}</h3>
<h3>{{ object.blurb }}</h3> <h3>{{ object.blurb }}</h3>
<button href="{% url 'bookshelf:edit-book' object.id %}">Edit Book</button> <br>
<a href="/home/">Home</a> <a href="/home/">Home</a>
<a href="/home/books/">Books</a> <a href="/home/books/">Books</a>
<a href="/home/authors/">Authors</a> <a href="/home/authors/">Authors</a>
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</ul> </ul>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<form action="home/authors" method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form }} {{ form }}
<input type="submit" value="Save Changes"> <input type="submit" value="Save Changes">
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</ul> </ul>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<form action="home/books" method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{{ form }} {{ form }}
<input type="submit" value="Save Changes"> <input type="submit" value="Save Changes">
......
...@@ -6,14 +6,14 @@ from .views import (BooksView, AuthorsView, BookDetailView, AuthorDetailView, ...@@ -6,14 +6,14 @@ from .views import (BooksView, AuthorsView, BookDetailView, AuthorDetailView,
urlpatterns = [ urlpatterns = [
path('', views.home_view, name='home'), path('', views.home_view, name='home'),
path('books/add/', BookCreateView.as_view(), name='add-book'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
path('books/<int:pk>/edit/', BookUpdateView.as_view(), name='edit-book'),
path('authors/<int:pk>/edit/', AuthorUpdateView.as_view(), name='edit-author'),
path('books/', BooksView.as_view(), name='book-list'), path('books/', BooksView.as_view(), name='book-list'),
path('authors/', AuthorsView.as_view(), name='author-list'), path('authors/', AuthorsView.as_view(), name='author-list'),
path('books/<int:pk>/details', BookDetailView.as_view(), name='book-detail'), path('books/<int:pk>/details/', BookDetailView.as_view(), name='book-detail'),
path('authors/<int:author_id>/details/', AuthorDetailView.as_view(), name='author-detail'), path('authors/<int:author_id>/details/', AuthorDetailView.as_view(), name='author-detail'),
path('books/add/', BookCreateView.as_view(), name='add-book'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
path('books/<int:pk>/edit', BookUpdateView.as_view(), name='edit-book'),
path('authors/<int:pk>/edit', AuthorUpdateView.as_view(), name='edit-author'),
] ]
app_name = "bookshelf" app_name = "bookshelf"
...@@ -4,6 +4,7 @@ from django.http import HttpResponse ...@@ -4,6 +4,7 @@ from django.http import HttpResponse
from django.views import View from django.views import View
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.urls import reverse
from django.views.generic.edit import CreateView, UpdateView from django.views.generic.edit import CreateView, UpdateView
...@@ -34,18 +35,26 @@ class BookCreateView(CreateView): ...@@ -34,18 +35,26 @@ class BookCreateView(CreateView):
model = Books model = Books
fields = '__all__' fields = '__all__'
template_name = 'bookshelf/add-book.html' template_name = 'bookshelf/add-book.html'
def get_success_url(self):
return reverse('bookshelf:book-detail', kwargs={'pk': self.object.pk})
class BookUpdateView(UpdateView): class BookUpdateView(UpdateView):
model = Books model = Books
fields = '__all__' fields = '__all__'
template_name = 'bookshelf/edit-book.html' template_name = 'bookshelf/edit-book.html'
def get_success_url(self):
return reverse('bookshelf:book-detail', kwargs={'pk': self.object.pk})
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'
def get_success_url(self):
return reverse('bookshelf:author-detail', kwargs={'author_id': self.object.pk})
class AuthorUpdateView(UpdateView): class AuthorUpdateView(UpdateView):
model = Books model = Books
fields = '__all__' fields = '__all__'
template_name = 'bookshelf/edit-author.html' template_name = 'bookshelf/edit-author.html'
def get_success_url(self):
return reverse('bookshelf:author-detail', kwargs={'author_id': self.object.pk})
\ 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