Complete add htmls alongside views urls, modified model

parent 19d79024
from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator, MinLengthValidator, MaxLengthValidator, int_list_validator
import datetime
from django.urls import reverse
class Author(models.Model):
default_string = ""
......@@ -13,6 +14,9 @@ class Author(models.Model):
def __str__(self):
return '{} {}'.format(self.first_name, self.last_name)
def get_absolute_url(self):
return reverse('bookshelf:author_details', kwargs={'author_id': self.id})
class Books(models.Model):
default_string = ""
title = models.CharField(max_length = 200, default = default_string)
......@@ -24,3 +28,6 @@ class Books(models.Model):
def __str__(self):
return '{}'.format(self.title)
def get_absolute_url(self):
return reverse('bookshelf:book_details', kwargs={'book_id': self.id})
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{form.as_p}}
<input type ="submit" value="Add Author">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{form.as_p}}
<input type ="submit" value="Add Book">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
\ No newline at end of file
......@@ -11,5 +11,7 @@
<br />
<a href = "../books/">Books</a>
<a href = "../authors/">Authors</a>
<a href = "../books/add">Add Book</a>
<a href = "../authors/add">Add Authors</a>
</p>
{% endblock %}
\ No newline at end of file
......@@ -7,6 +7,10 @@ urlpatterns = [
path('authors/', views.author_view.as_view(), name='authors'),
path('books/<int:book_id>/details/', views.bookdetails_view.as_view(), name='book_details'),
path('authors/<int:author_id>/details/', views.authordetails_view.as_view(), name='author_details'),
path('books/add', views.addbooks_view.as_view(), name='add_book'),
path('authors/add', views.addauthors_view.as_view(), name='add_author'),
#path('books//<int:book_id>/edit/', views_editbook_view.as_view(), name='edit_book'),
#path('books//<int:author_id>/edit/', views_editauthor_view.as_view(), name='edit_author'),
]
app_name = "bookshelf"
\ No newline at end of file
from django.views.generic.edit import CreateView
from django.http import HttpResponse, Http404
from django.shortcuts import render
from django.views import View
......@@ -37,4 +38,14 @@ class authordetails_view(View):
"author": displayauthor,
"books": books
}
return render(request, 'bookshelf/author_details.html', context)
\ No newline at end of file
return render(request, 'bookshelf/author_details.html', context)
class addbooks_view(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class addauthors_view(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-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