Commit d93d3a6e authored by Nics De Vega's avatar Nics De Vega

Created edit pages for books and authors

parent afc77108
...@@ -5,10 +5,10 @@ from .models import Book, Author ...@@ -5,10 +5,10 @@ from .models import Book, Author
class BookForm(forms.ModelForm): class BookForm(forms.ModelForm):
class Meta: class Meta:
model = Book model = Book
fields = ['Title', 'Author', 'Publisher','Year Published','ISBN','Blurb'] fields = '__all__'
class AuthorForm(forms.ModelForm): class AuthorForm(forms.ModelForm):
class Meta: class Meta:
model = Author model = Author
fields = ['First Name', 'Last Name', 'Age','Nationality','Bio'] fields = '__all__'
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
{% block title %}Add New Author{% endblock %} {% block title %}Add New Author{% endblock %}
{% block content %} {% block content %}
<br> <br>
<form action="authors/<int:pk>/details/" method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{% for field in form %} {% for field in form %}
{{field.label}}:{{field}} <br><br> {{field.label}}:{{field}} <br><br>
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
{% block title %}Add New Book{% endblock %} {% block title %}Add New Book{% endblock %}
{% block content %} {% block content %}
<br> <br>
<form action="books/<int:pk>/details/" method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{% for field in form %} {% for field in form %}
{{field.label}}:{{field}} <br><br> {{field.label}}:{{field}} <br><br>
{% endfor %} {% endfor %}
<input type="submit" value="Add book"> <input type="submit" value="Add Book">
</form> </form>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
<li class="list-group-item"><h4>{{object.age}}</h4></li> <li class="list-group-item"><h4>{{object.age}}</h4></li>
<li class="list-group-item"><h4>{{object.nationality}}</h4></li> <li class="list-group-item"><h4>{{object.nationality}}</h4></li>
<li class="list-group-item"><p>{{object.bio}}</p></li> <li class="list-group-item"><p>{{object.bio}}</p></li>
<li class="list-group-item"><a href="/bookshelf/authors/{{object.pk}}/edit">Edit Author</a></li>
<li class="list-group-item"><h3>Books by {{object.first_name}} {{object.last_name}} I love:</h3></li> <li class="list-group-item"><h3>Books by {{object.first_name}} {{object.last_name}} I love:</h3></li>
<li class="list-group-item"> <li class="list-group-item">
<ul> <ul>
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
<li class="list-group-item"><h4>{{object.year_published}}</h4></li> <li class="list-group-item"><h4>{{object.year_published}}</h4></li>
<li class="list-group-item"><h4>{{object.ISBN}}</h4></li> <li class="list-group-item"><h4>{{object.ISBN}}</h4></li>
<li class="list-group-item"><p>{{object.blurb}}</p></li> <li class="list-group-item"><p>{{object.blurb}}</p></li>
<li class="list-group-item"><a href="/bookshelf/books/{{object.pk}}/edit">Edit Book</a></li>
<li class="list-group-item"> <li class="list-group-item">
<h2 class="text-center"> <h2 class="text-center">
<small> <small>
...@@ -20,4 +23,4 @@ ...@@ -20,4 +23,4 @@
</h2> </h2>
</li> </li>
</ul> </ul>
{% endblock %} {% endblock %}]
\ No newline at end of file \ No newline at end of file
...@@ -3,12 +3,11 @@ ...@@ -3,12 +3,11 @@
{% block title %}Edit Author{% endblock %} {% block title %}Edit Author{% endblock %}
{% block content %} {% block content %}
<br> <br>
<form action="/" method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{% for field in form %} {% for field in form %}
{{field.label}}:{{field}} <br><br> {{field.label}}:{{field}} <br><br>
{% endfor %} {% endfor %}
<input type="submit" value="Submit"> <input type="submit" value="Save Changes">
</form> </form>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -3,12 +3,11 @@ ...@@ -3,12 +3,11 @@
{% block title %}Edit Book{% endblock %} {% block title %}Edit Book{% endblock %}
{% block content %} {% block content %}
<br> <br>
<form action="/" method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
{% for field in form %} {% for field in form %}
{{field.label}}:{{field}} <br><br> {{field.label}}:{{field}} <br><br>
{% endfor %} {% endfor %}
<input type="submit" value="Submit"> <input type="submit" value="Save Changes">
</form> </form>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -11,13 +11,13 @@ urlpatterns = [ ...@@ -11,13 +11,13 @@ urlpatterns = [
path('books/',BooksView.as_view(),name='books'), path('books/',BooksView.as_view(),name='books'),
path('books/<int:pk>/details/',BooksDetailView.as_view(),name='book_details'), path('books/<int:pk>/details/',BooksDetailView.as_view(),name='book_details'),
path('books/add/',BooksCreateView.as_view(),name='add_book'), path('books/add/',BooksCreateView.as_view(),name='add-book'),
path('books/<int:pk>/edit/',BooksUpdateView.as_view(),name='update_book'), path('books/<int:pk>/edit/',BooksUpdateView.as_view(),name='update-book'),
path('authors/',AuthorsView.as_view(),name='authors'), path('authors/',AuthorsView.as_view(),name='authors'),
path('authors/<int:pk>/details/',AuthorsDetailView.as_view(),name='author_details'), path('authors/<int:pk>/details/',AuthorsDetailView.as_view(),name='author_details'),
path('authors/add/',AuthorsCreateView.as_view(),name='add_author'), path('authors/add/',AuthorsCreateView.as_view(),name='add-author'),
path('authors/<int:pk>/edit/',AuthorsUpdateView.as_view(),name='update_author'), path('authors/<int:pk>/edit/',AuthorsUpdateView.as_view(),name='update-author'),
] ]
......
...@@ -43,6 +43,6 @@ class AuthorsCreateView(CreateView): ...@@ -43,6 +43,6 @@ class AuthorsCreateView(CreateView):
template_name = "bookshelf/add-author.html" template_name = "bookshelf/add-author.html"
class AuthorsUpdateView(UpdateView): class AuthorsUpdateView(UpdateView):
model = Book model = Author
fields = '__all__' fields = '__all__'
template_name = "bookshelf/edit-author.html" 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