└── blog ├── .DS_Store ├── blog ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── settings.cpython-38.pyc │ ├── urls.cpython-38.pyc │ └── wsgi.cpython-38.pyc ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── bookstore ├── .DS_Store ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── admin.cpython-38.pyc │ ├── apps.cpython-38.pyc │ ├── decorators.cpython-38.pyc │ ├── filters.cpython-38.pyc │ ├── forms.cpython-38.pyc │ ├── models.cpython-38.pyc │ ├── signals.cpython-38.pyc │ ├── urls.cpython-38.pyc │ └── views.cpython-38.pyc ├── admin.py ├── apps.py ├── decorators.py ├── filters.py ├── forms.py ├── migrations │ ├── 0001_initial.py │ ├── 0002_book_order.py │ ├── 0003_auto_20200920_2106.py │ ├── 0004_book_tags.py │ ├── 0005_customer_user.py │ ├── 0006_customer_avatar.py │ ├── 0007_auto_20200926_1542.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-38.pyc │ │ ├── 0002_book_order.cpython-38.pyc │ │ ├── 0003_auto_20200920_2106.cpython-38.pyc │ │ ├── 0004_book_tags.cpython-38.pyc │ │ ├── 0005_customer_user.cpython-38.pyc │ │ ├── 0006_customer_avatar.cpython-38.pyc │ │ ├── 0007_auto_20200926_1542.cpython-38.pyc │ │ └── __init__.cpython-38.pyc ├── models.py ├── signals.py ├── templates │ ├── .DS_Store │ └── bookstore │ │ ├── books.html │ │ ├── customer.html │ │ ├── dashboard.html │ │ ├── delete_form.html │ │ ├── login.html │ │ ├── main.html │ │ ├── my_order_form.html │ │ ├── navbar.html │ │ ├── password_reset.html │ │ ├── password_reset_done.html │ │ ├── password_reset_form.html │ │ ├── password_reset_sent.html │ │ ├── profile.html │ │ ├── profile_info.html │ │ └── register.html ├── tests.py ├── urls.py └── views.py ├── db.sqlite3 ├── manage.py └── static ├── .DS_Store ├── css └── style.css └── images ├── .DS_Store ├── 1.jpg ├── 1_KGyfYbC.jpg ├── bP7gDPl1.jpg ├── bP7gDPl1_2aEMZQQ.jpg ├── book.png └── preson.png /blog/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/.DS_Store -------------------------------------------------------------------------------- /blog/blog/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/blog/__init__.py -------------------------------------------------------------------------------- /blog/blog/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/blog/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /blog/blog/__pycache__/settings.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/blog/__pycache__/settings.cpython-38.pyc -------------------------------------------------------------------------------- /blog/blog/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/blog/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /blog/blog/__pycache__/wsgi.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/blog/__pycache__/wsgi.cpython-38.pyc -------------------------------------------------------------------------------- /blog/blog/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for blog 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/3.1/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', 'blog.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /blog/blog/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for blog project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.1.1. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.1/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'v!u)j1=c$$lise*g-s=5rrxdhzs)&h*l7z7mvgbp(c--y*z_4p' 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 | 'bookstore', 41 | 'django_filters', 42 | # 'bookstore.apps.BookstoreConfig' 43 | 44 | ] 45 | 46 | MIDDLEWARE = [ 47 | 'django.middleware.security.SecurityMiddleware', 48 | 'django.contrib.sessions.middleware.SessionMiddleware', 49 | 'django.middleware.common.CommonMiddleware', 50 | 'django.middleware.csrf.CsrfViewMiddleware', 51 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 52 | 'django.contrib.messages.middleware.MessageMiddleware', 53 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 54 | ] 55 | 56 | ROOT_URLCONF = 'blog.urls' 57 | 58 | TEMPLATES = [ 59 | { 60 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 61 | 'DIRS': [], 62 | 'APP_DIRS': True, 63 | 'OPTIONS': { 64 | 'context_processors': [ 65 | 'django.template.context_processors.debug', 66 | 'django.template.context_processors.request', 67 | 'django.contrib.auth.context_processors.auth', 68 | 'django.contrib.messages.context_processors.messages', 69 | ], 70 | }, 71 | }, 72 | ] 73 | 74 | WSGI_APPLICATION = 'blog.wsgi.application' 75 | 76 | 77 | # Database 78 | # https://docs.djangoproject.com/en/3.1/ref/settings/#databases 79 | 80 | DATABASES = { 81 | 'default': { 82 | 'ENGINE': 'django.db.backends.sqlite3', 83 | 'NAME': BASE_DIR / 'db.sqlite3', 84 | } 85 | } 86 | 87 | 88 | 89 | 90 | # DATABASES = { 91 | # 'default': { 92 | # 'ENGINE': 'django.db.backends.postgresql', 93 | # 'NAME': 'MYData', 94 | # 'USER': 'postgres', 95 | # 'PASSWORD': 'Muhammed1984', 96 | # 'HOST':'localhost', 97 | # 'PORT':'5432' 98 | # } 99 | # } 100 | 101 | 102 | # Password validation 103 | # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators 104 | 105 | AUTH_PASSWORD_VALIDATORS = [ 106 | { 107 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 108 | }, 109 | { 110 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 111 | }, 112 | { 113 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 114 | }, 115 | { 116 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 117 | }, 118 | ] 119 | 120 | 121 | # Internationalization 122 | # https://docs.djangoproject.com/en/3.1/topics/i18n/ 123 | 124 | LANGUAGE_CODE = 'en-us' 125 | 126 | TIME_ZONE = 'UTC' 127 | 128 | USE_I18N = True 129 | 130 | USE_L10N = True 131 | 132 | USE_TZ = True 133 | 134 | 135 | # Static files (CSS, JavaScript, Images) 136 | # https://docs.djangoproject.com/en/3.1/howto/static-files/ 137 | import os 138 | 139 | STATIC_URL = '/static/' 140 | 141 | MEDIA_URL = '/images/' 142 | 143 | STATICFILES_DIRS = [ 144 | os.path.join(BASE_DIR, 'static') 145 | ] 146 | 147 | 148 | MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images') 149 | 150 | 151 | 152 | EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' 153 | EMAIL_HOST = 'smtp.gmail.com' 154 | EMAIL_PORT = 587 155 | EMAIL_USE_TLS = True 156 | EMAIL_HOST_USER = 'test@gmail.com' 157 | EMAIL_HOST_PASSWORD = '1234567' 158 | 159 | 160 | GOOGLE_RECAPTCHA_SECRET_KEY= '6Ldq_9AZAAAAAEBLVbknRrtgQfTZVBcDZXNgG6jL' -------------------------------------------------------------------------------- /blog/blog/urls.py: -------------------------------------------------------------------------------- 1 | """blog URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.1/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path,include 18 | 19 | 20 | from django.conf.urls.static import static 21 | 22 | from django.conf import settings 23 | 24 | 25 | 26 | 27 | urlpatterns = [ 28 | path('admin/', admin.site.urls), 29 | path('' , include('bookstore.urls')) 30 | 31 | ] 32 | 33 | urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT) 34 | -------------------------------------------------------------------------------- /blog/blog/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for blog 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/3.1/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', 'blog.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /blog/bookstore/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/.DS_Store -------------------------------------------------------------------------------- /blog/bookstore/__init__.py: -------------------------------------------------------------------------------- 1 | default_app_config = "bookstore.apps.BookstoreConfig" -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/admin.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/admin.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/apps.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/apps.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/decorators.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/decorators.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/filters.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/filters.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/forms.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/forms.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/models.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/models.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/signals.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/signals.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/__pycache__/views.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/__pycache__/views.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | 5 | 6 | from .models import * 7 | 8 | admin.site.register(Customer) 9 | 10 | admin.site.register(Book) 11 | 12 | admin.site.register(Order) 13 | admin.site.register(Tag) -------------------------------------------------------------------------------- /blog/bookstore/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class BookstoreConfig(AppConfig): 5 | name = 'bookstore' 6 | 7 | def ready(self): 8 | import bookstore.signals 9 | -------------------------------------------------------------------------------- /blog/bookstore/decorators.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import redirect 2 | from django.http import HttpResponse 3 | 4 | 5 | 6 | 7 | def notLoggedUsers(view_func): 8 | def wrapper_func(request , *args,**kwargs): 9 | if request.user.is_authenticated: 10 | return redirect('home') 11 | else: 12 | return view_func(request , *args,**kwargs) 13 | return wrapper_func 14 | 15 | 16 | def allowedUsers(allowedGroups=[]): 17 | def decorator(view_func): 18 | def wrapper_func(request , *args,**kwargs): 19 | group = None 20 | if request.user.groups.exists(): 21 | group = request.user.groups.all()[0].name 22 | if group in allowedGroups: 23 | return view_func(request , *args,**kwargs) 24 | else: 25 | return redirect('user_profile') 26 | 27 | return wrapper_func 28 | return decorator 29 | 30 | 31 | 32 | 33 | def forAdmins(view_func): 34 | def wrapper_func(request , *args,**kwargs): 35 | group = None 36 | if request.user.groups.exists(): 37 | group = request.user.groups.all()[0].name 38 | if group == 'admin': 39 | return view_func(request , *args,**kwargs) 40 | if group == 'customer': 41 | return redirect('user_profile') 42 | 43 | return wrapper_func -------------------------------------------------------------------------------- /blog/bookstore/filters.py: -------------------------------------------------------------------------------- 1 | import django_filters 2 | 3 | from .models import * 4 | 5 | class OrderFilter(django_filters.FilterSet): 6 | class Meta: 7 | model = Order 8 | fields = '__all__' 9 | # fields = ['book' , 'status'] 10 | # exclude = ['book' , 'status'] -------------------------------------------------------------------------------- /blog/bookstore/forms.py: -------------------------------------------------------------------------------- 1 | from django.forms import ModelForm 2 | from django.contrib.auth.models import User 3 | from django.contrib.auth.forms import UserCreationForm 4 | 5 | 6 | from .models import Order , Customer 7 | 8 | class OrderForm(ModelForm): 9 | class Meta: 10 | model = Order 11 | fields ="__all__" 12 | 13 | 14 | class CustomerForm(ModelForm): 15 | class Meta: 16 | model = Customer 17 | fields ="__all__" 18 | exclude = ['user' ] 19 | 20 | 21 | class CreateNewUser(UserCreationForm): 22 | class Meta: 23 | model = User 24 | fields =['username','email','password1','password2'] 25 | 26 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-20 20:33 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='Customer', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('name', models.CharField(max_length=190, null=True)), 19 | ('email', models.CharField(max_length=190, null=True)), 20 | ('phone', models.CharField(max_length=190, null=True)), 21 | ('age', models.CharField(max_length=190, null=True)), 22 | ('date_created', models.DateTimeField(auto_now_add=True, null=True)), 23 | ], 24 | ), 25 | ] 26 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0002_book_order.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-20 20:51 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('bookstore', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='Book', 15 | fields=[ 16 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 17 | ('name', models.CharField(max_length=190, null=True)), 18 | ('author', models.CharField(max_length=190, null=True)), 19 | ('price', models.FloatField(null=True)), 20 | ('category', models.CharField(choices=[('Classics', 'Classics'), ('Comic Book', 'Comic Book'), ('Fantasy', 'Fantasy'), ('Horror', 'Horror')], max_length=190, null=True)), 21 | ('description', models.CharField(max_length=200, null=True)), 22 | ('date_created', models.DateTimeField(auto_now_add=True, null=True)), 23 | ], 24 | ), 25 | migrations.CreateModel( 26 | name='Order', 27 | fields=[ 28 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 29 | ('date_created', models.DateTimeField(auto_now_add=True, null=True)), 30 | ('status', models.CharField(choices=[('Pending', 'Pending'), ('Delivered', 'Delivered'), ('in progress', 'in progress'), ('out of order', 'out of order')], max_length=200, null=True)), 31 | ], 32 | ), 33 | ] 34 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0003_auto_20200920_2106.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-20 21:06 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('bookstore', '0002_book_order'), 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Tag', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('name', models.CharField(max_length=190, null=True)), 19 | ], 20 | ), 21 | migrations.AddField( 22 | model_name='order', 23 | name='book', 24 | field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='bookstore.book'), 25 | ), 26 | migrations.AddField( 27 | model_name='order', 28 | name='customer', 29 | field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='bookstore.customer'), 30 | ), 31 | migrations.AddField( 32 | model_name='order', 33 | name='tags', 34 | field=models.ManyToManyField(to='bookstore.Tag'), 35 | ), 36 | ] 37 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0004_book_tags.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-20 21:09 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('bookstore', '0003_auto_20200920_2106'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='book', 15 | name='tags', 16 | field=models.ManyToManyField(to='bookstore.Tag'), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0005_customer_user.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-23 18:46 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 12 | ('bookstore', '0004_book_tags'), 13 | ] 14 | 15 | operations = [ 16 | migrations.AddField( 17 | model_name='customer', 18 | name='user', 19 | field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), 20 | ), 21 | ] 22 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0006_customer_avatar.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-26 14:48 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('bookstore', '0005_customer_user'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='customer', 15 | name='avatar', 16 | field=models.ImageField(blank=True, null=True, upload_to=''), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/0007_auto_20200926_1542.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.1 on 2020-09-26 15:42 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('bookstore', '0006_customer_avatar'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='customer', 15 | name='avatar', 16 | field=models.ImageField(blank=True, default='preson.png', null=True, upload_to=''), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /blog/bookstore/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__init__.py -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0001_initial.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0001_initial.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0002_book_order.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0002_book_order.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0003_auto_20200920_2106.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0003_auto_20200920_2106.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0004_book_tags.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0004_book_tags.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0005_customer_user.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0005_customer_user.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0006_customer_avatar.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0006_customer_avatar.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/0007_auto_20200926_1542.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/0007_auto_20200926_1542.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/migrations/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/migrations/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /blog/bookstore/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import User 3 | # Create your models here. 4 | 5 | 6 | class Customer(models.Model): 7 | user = models.OneToOneField(User,null=True, on_delete=models.CASCADE) 8 | name = models.CharField(max_length=190, null=True) 9 | email = models.CharField(max_length=190, null=True) 10 | phone = models.CharField(max_length=190, null=True) 11 | age = models.CharField(max_length=190, null=True) 12 | avatar = models.ImageField(blank=True, null=True, default="preson.png") 13 | date_created = models.DateTimeField(auto_now_add=True, null=True) 14 | 15 | def __str__(self): 16 | return self.name 17 | 18 | 19 | 20 | class Tag(models.Model): 21 | name = models.CharField(max_length=190, null=True) 22 | 23 | def __str__(self): 24 | return self.name 25 | 26 | 27 | class Book(models.Model): 28 | CATEGORY = ( 29 | ('Classics','Classics'), 30 | ('Comic Book','Comic Book'), 31 | ('Fantasy','Fantasy'), 32 | ('Horror','Horror') 33 | ) 34 | name = models.CharField(max_length=190, null=True) 35 | author = models.CharField(max_length=190, null=True) 36 | price = models.FloatField( null=True) 37 | category = models.CharField(max_length=190, null=True, choices=CATEGORY) 38 | description = models.CharField(max_length=200, null=True) 39 | tags = models.ManyToManyField(Tag) 40 | date_created = models.DateTimeField(auto_now_add=True, null=True) 41 | 42 | def __str__(self): 43 | return self.name 44 | 45 | 46 | 47 | 48 | 49 | class Order(models.Model): 50 | STATUS= ( 51 | ('Pending','Pending'), 52 | ('Delivered','Delivered'), 53 | ('in progress','in progress'), 54 | ('out of order','out of order') 55 | ) 56 | 57 | customer = models.ForeignKey(Customer, null=True, on_delete=models.SET_NULL) 58 | book = models.ForeignKey(Book, null=True, on_delete=models.SET_NULL) 59 | tags = models.ManyToManyField(Tag) 60 | date_created = models.DateTimeField(auto_now_add=True, null=True) 61 | status = models.CharField(max_length=200, null=True,choices=STATUS) -------------------------------------------------------------------------------- /blog/bookstore/signals.py: -------------------------------------------------------------------------------- 1 | from django.db.models.signals import post_save 2 | from django.contrib.auth.models import User, Group 3 | from .models import Customer 4 | 5 | 6 | def customer_create_profile(sender , instance ,created , **kwargs): 7 | if created: 8 | group = Group.objects.get(name="customer") 9 | instance.groups.add(group) 10 | 11 | Customer.objects.create( 12 | user = instance, 13 | name= instance.username 14 | ) 15 | 16 | print('Customer profile created ! ') 17 | 18 | post_save.connect(customer_create_profile, sender=User) -------------------------------------------------------------------------------- /blog/bookstore/templates/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhammedessa/Django_Python_tutorial/a913ffe7c33aecf06b9672c3c4f2faead90422d6/blog/bookstore/templates/.DS_Store -------------------------------------------------------------------------------- /blog/bookstore/templates/bookstore/books.html: -------------------------------------------------------------------------------- 1 | {% extends 'bookstore/main.html'%} 2 | 3 | {% block content %} 4 | 5 |
Name | 14 |Price | 15 |Author | 16 |
---|---|---|
{{item.name}} | 23 |{{item.price}} | 24 |{{item.author}} | 25 |
Some quick example text to build on the card title and make up the bulk of the card's content.
104 | Card link 105 | Another link 106 |Some quick example text to build on the card title and make up the bulk of the card's content.
115 | Card link 116 | Another link 117 |Check your Email inbox
5 |Book | 40 |Category | 41 |Date | 42 |status | 43 |
---|---|---|---|
{{item.book}} | 49 |{{item.book.category}} | 50 |{{item.date_created}} | 51 |{{item.status}} | 52 | 53 |