Skip to content

Commit bc7c06f

Browse files
first commit
0 parents  commit bc7c06f

32 files changed

+544
-0
lines changed

Bookapp/__init__.py

Whitespace-only changes.
134 Bytes
Binary file not shown.
175 Bytes
Binary file not shown.
413 Bytes
Binary file not shown.
446 Bytes
Binary file not shown.
367 Bytes
Binary file not shown.
1.36 KB
Binary file not shown.

Bookapp/admin.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

Bookapp/apps.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class BookappConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'Bookapp'

Bookapp/migrations/0001_initial.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 4.2.9 on 2024-02-01 16:40
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = [
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='Book',
16+
fields=[
17+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('title', models.CharField(max_length=30)),
19+
('auther', models.CharField(max_length=40)),
20+
('price', models.IntegerField()),
21+
],
22+
),
23+
]

Bookapp/migrations/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.

Bookapp/models.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.db import models
2+
3+
# Create your models here.
4+
class Book(models.Model):
5+
title = models.CharField(max_length=30)
6+
auther = models.CharField(max_length=40)
7+
price = models.IntegerField()

Bookapp/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

Bookapp/urls.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.urls import path
2+
from Bookapp import views
3+
4+
urlpatterns = [
5+
path('home',views.homepage),
6+
path('register',views.addbook),
7+
path('delete/<bookid>',views.deleteBook),
8+
path('update/<bookid>',views.updateBook),
9+
]

Bookapp/views.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from django.shortcuts import render,redirect
2+
from Bookapp.models import Book
3+
4+
# Create your views here.
5+
def homepage(request):
6+
data = Book.objects.all()
7+
context = {}
8+
context['books'] = data
9+
return render(request,'home.html',context)
10+
11+
def addbook(request):
12+
if request.method=="GET":
13+
print("with in GET")
14+
return render(request,'register.html')
15+
else:
16+
print("Within in POST")
17+
t = request.POST['title']
18+
a = request.POST['auther']
19+
p = request.POST['price']
20+
b = Book.objects.create(title=t,auther=a,price=p)
21+
b.save()
22+
#print("Bokk added",t,a,p)
23+
#return render(request,'home.html')
24+
return redirect("/home")
25+
26+
def deleteBook(request,bookid):
27+
b = Book.objects.filter(id = bookid)
28+
b.delete()
29+
return redirect("/home")
30+
31+
def updateBook(request,bookid):
32+
if request.method == "GET":
33+
#print("Updated book id",bookid)
34+
b = Book.objects.filter(id = bookid)
35+
context = {}
36+
context['book'] = b[0]
37+
return render(request,'updateBook.html',context)
38+
else:
39+
t = request.POST['title']
40+
a = request.POST['auther']
41+
p = request.POST['price']
42+
b = Book.objects.filter(id = bookid)
43+
b.update(title=t,auther=a,price=p)
44+
return redirect('/home')
45+
46+

Bookcrud/__init__.py

Whitespace-only changes.
135 Bytes
Binary file not shown.
2.38 KB
Binary file not shown.
975 Bytes
Binary file not shown.
540 Bytes
Binary file not shown.

Bookcrud/asgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for Bookcrud project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Bookcrud.settings')
15+
16+
application = get_asgi_application()

Bookcrud/settings.py

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
"""
2+
Django settings for Bookcrud project.
3+
4+
Generated by 'django-admin startproject' using Django 4.2.9.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.2/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/4.2/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
import os
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
print(BASE_DIR)
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'django-insecure-03edowqcj09)v@b^fnqb#*ptrad93b&l(acz018hd3n&4s9a0j'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'django.contrib.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
'Bookapp'
41+
]
42+
43+
MIDDLEWARE = [
44+
'django.middleware.security.SecurityMiddleware',
45+
'django.contrib.sessions.middleware.SessionMiddleware',
46+
'django.middleware.common.CommonMiddleware',
47+
'django.middleware.csrf.CsrfViewMiddleware',
48+
'django.contrib.auth.middleware.AuthenticationMiddleware',
49+
'django.contrib.messages.middleware.MessageMiddleware',
50+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
51+
]
52+
53+
ROOT_URLCONF = 'Bookcrud.urls'
54+
55+
TEMPLATES = [
56+
{
57+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
58+
'DIRS': [os.path.join(BASE_DIR,'templates')],
59+
'APP_DIRS': True,
60+
'OPTIONS': {
61+
'context_processors': [
62+
'django.template.context_processors.debug',
63+
'django.template.context_processors.request',
64+
'django.contrib.auth.context_processors.auth',
65+
'django.contrib.messages.context_processors.messages',
66+
],
67+
},
68+
},
69+
]
70+
71+
WSGI_APPLICATION = 'Bookcrud.wsgi.application'
72+
73+
74+
# Database
75+
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases
76+
77+
# DATABASES = {
78+
# 'default': {
79+
# 'ENGINE': 'django.db.backends.sqlite3',
80+
# 'NAME': BASE_DIR / 'db.sqlite3',
81+
# }
82+
# }
83+
84+
DATABASES = {
85+
'default': {
86+
'ENGINE': 'django.db.backends.mysql',
87+
'NAME': 'django_book',
88+
'HOST': 'localhost',
89+
'USER': 'root',
90+
'PASSWORD': 'root',
91+
'PORT': '3306'
92+
93+
}
94+
}
95+
96+
97+
# Password validation
98+
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
99+
100+
AUTH_PASSWORD_VALIDATORS = [
101+
{
102+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
103+
},
104+
{
105+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
106+
},
107+
{
108+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
109+
},
110+
{
111+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
112+
},
113+
]
114+
115+
116+
# Internationalization
117+
# https://docs.djangoproject.com/en/4.2/topics/i18n/
118+
119+
LANGUAGE_CODE = 'en-us'
120+
121+
TIME_ZONE = 'UTC'
122+
123+
USE_I18N = True
124+
125+
USE_TZ = True
126+
127+
128+
# Static files (CSS, JavaScript, Images)
129+
# https://docs.djangoproject.com/en/4.2/howto/static-files/
130+
131+
STATIC_URL = 'static/'
132+
STATICFILES_DIRS=[BASE_DIR / "static"]
133+
# Default primary key field type
134+
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
135+
136+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

Bookcrud/urls.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
URL configuration for Bookcrud project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/4.2/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
17+
from django.contrib import admin
18+
from django.urls import path,include
19+
20+
urlpatterns = [
21+
path('admin/', admin.site.urls),
22+
path('',include('Bookapp.urls'))
23+
]

Bookcrud/wsgi.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for Bookcrud project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Bookcrud.settings')
15+
16+
application = get_wsgi_application()

db.sqlite3

Whitespace-only changes.

manage.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Bookcrud.settings')
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()

static/images/book1.jpg

937 KB
Loading

0 commit comments

Comments
 (0)