├── .DS_Store ├── .gitattributes ├── .gitignore ├── Custom-User-Model-Proxy-Model ├── core │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── settings.cpython-39.pyc │ │ └── urls.cpython-39.pyc │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── db.sqlite3 ├── manage.py └── user │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-39.pyc │ ├── admin.cpython-39.pyc │ ├── apps.cpython-39.pyc │ └── models.cpython-39.pyc │ ├── admin.py │ ├── apps.py │ ├── fixtures │ └── db_admin_fixture.json │ ├── migrations │ ├── 0001_initial.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-39.pyc │ │ └── __init__.cpython-39.pyc │ ├── models.py │ ├── tests.py │ └── views.py ├── LICENSE ├── case-study-1-query-1 ├── db.sqlite3 ├── ecommerce │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── settings.cpython-39.pyc │ │ ├── urls.cpython-39.pyc │ │ └── wsgi.cpython-39.pyc │ ├── asgi.py │ ├── inventory │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-39.pyc │ │ │ ├── admin.cpython-39.pyc │ │ │ ├── apps.cpython-39.pyc │ │ │ ├── models.cpython-39.pyc │ │ │ ├── urls.cpython-39.pyc │ │ │ └── views.cpython-39.pyc │ │ ├── admin.py │ │ ├── apps.py │ │ ├── fixtures │ │ │ ├── db_admin_fixture_50.json │ │ │ ├── db_attribute_fixture_50.json │ │ │ ├── db_attribute_value_fixture_50.json │ │ │ ├── db_attribute_values_fixture_50.json │ │ │ ├── db_category_fixture_50.json │ │ │ ├── db_image_fixture_50.json │ │ │ ├── db_inventory_fixture_50.json │ │ │ ├── db_product_category_fixture_50.json │ │ │ ├── db_product_fixture_50.json │ │ │ └── db_stock_control_fixture_50.json │ │ ├── management │ │ │ └── commands │ │ │ │ ├── __pycache__ │ │ │ │ └── load-fixtures.cpython-39.pyc │ │ │ │ └── load-fixtures.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ ├── __init__.py │ │ │ └── __pycache__ │ │ │ │ ├── 0001_initial.cpython-39.pyc │ │ │ │ └── __init__.cpython-39.pyc │ │ ├── models.py │ │ ├── templates │ │ │ └── grid-output.html │ │ ├── tests.py │ │ ├── urls.py │ │ └── views.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── manage.py ├── requirements.txt └── static │ └── assets │ ├── brand │ ├── bootstrap-logo-white.svg │ └── bootstrap-logo.svg │ └── dist │ ├── css │ ├── bootstrap.min.css │ ├── bootstrap.min.css.map │ ├── bootstrap.rtl.min.css │ └── bootstrap.rtl.min.css.map │ └── js │ ├── bootstrap.bundle.min.js │ └── bootstrap.bundle.min.js.map ├── case-study-1 ├── db.sqlite3 ├── ecommerce │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── settings.cpython-39.pyc │ │ ├── urls.cpython-39.pyc │ │ └── wsgi.cpython-39.pyc │ ├── asgi.py │ ├── inventory │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-39.pyc │ │ │ ├── admin.cpython-39.pyc │ │ │ ├── apps.cpython-39.pyc │ │ │ └── models.cpython-39.pyc │ │ ├── admin.py │ │ ├── apps.py │ │ ├── fixtures │ │ │ ├── db_admin_fixture_50.json │ │ │ ├── db_attribute_fixture_50.json │ │ │ ├── db_attribute_value_fixture_50.json │ │ │ ├── db_attribute_values_fixture_50.json │ │ │ ├── db_category_fixture_50.json │ │ │ ├── db_image_fixture_50.json │ │ │ ├── db_inventory_fixture_50.json │ │ │ ├── db_product_category_fixture_50.json │ │ │ ├── db_product_fixture_50.json │ │ │ └── db_stock_control_fixture_50.json │ │ ├── management │ │ │ └── commands │ │ │ │ ├── __pycache__ │ │ │ │ └── load-fixtures.cpython-39.pyc │ │ │ │ └── load-fixtures.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ ├── __init__.py │ │ │ └── __pycache__ │ │ │ │ ├── 0001_initial.cpython-39.pyc │ │ │ │ └── __init__.cpython-39.pyc │ │ ├── models.py │ │ ├── tests.py │ │ └── views.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py ├── choice-field-option ├── Starting_codebase.zip └── final_code.zip ├── codebase-0 ├── .DS_Store ├── core │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── settings.cpython-39.pyc │ │ ├── urls.cpython-39.pyc │ │ └── wsgi.cpython-39.pyc │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── inventory │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── admin.cpython-39.pyc │ │ ├── apps.cpython-39.pyc │ │ └── models.cpython-39.pyc │ ├── admin.py │ ├── apps.py │ ├── migrations │ │ ├── __init__.py │ │ └── __pycache__ │ │ │ ├── 0001_initial.cpython-39.pyc │ │ │ ├── 0002_alter_product_category_stock.cpython-39.pyc │ │ │ ├── 0002_alter_product_name.cpython-39.pyc │ │ │ ├── 0002_rename_name_product_the_name.cpython-39.pyc │ │ │ ├── 0003_brand_alter_product_name.cpython-39.pyc │ │ │ └── __init__.cpython-39.pyc │ ├── models.py │ ├── tests.py │ └── views.py ├── manage.py └── requirements.txt ├── codebase-1 └── code-base-1.zip ├── custom-user-model-ex1 ├── Base.zip ├── core │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── settings.cpython-39.pyc │ │ ├── urls.cpython-39.pyc │ │ └── wsgi.cpython-39.pyc │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── db.sqlite3 ├── manage.py └── user │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-39.pyc │ ├── admin.cpython-39.pyc │ ├── apps.cpython-39.pyc │ └── models.cpython-39.pyc │ ├── admin.py │ ├── apps.py │ ├── migrations │ ├── 0001_initial.py │ ├── 0002_student.py │ ├── 0003_teacher.py │ ├── 0004_studentprofile.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-39.pyc │ │ ├── 0002_alter_studentprofile_student_id.cpython-39.pyc │ │ ├── 0002_student.cpython-39.pyc │ │ ├── 0003_teacher.cpython-39.pyc │ │ ├── 0004_studentprofile.cpython-39.pyc │ │ └── __init__.cpython-39.pyc │ ├── models.py │ ├── tests.py │ └── views.py └── customer-user-model-add-user-fields ├── core ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-39.pyc │ ├── settings.cpython-39.pyc │ ├── urls.cpython-39.pyc │ └── wsgi.cpython-39.pyc ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── db.sqlite3 ├── manage.py ├── requirements.txt └── user ├── __init__.py ├── __pycache__ ├── __init__.cpython-39.pyc ├── admin.cpython-39.pyc ├── apps.cpython-39.pyc ├── models.cpython-39.pyc ├── urls.cpython-39.pyc └── views.cpython-39.pyc ├── admin.py ├── apps.py ├── fixtures └── db_admin_fixture.json ├── migrations ├── 0001_initial.py ├── __init__.py └── __pycache__ │ ├── 0001_initial.cpython-39.pyc │ └── __init__.cpython-39.pyc ├── models.py ├── templates └── profile.html ├── tests.py ├── urls.py └── views.py /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/.DS_Store -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | .DS_Store 4 | .DS_Store 5 | .DS_Store 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/Custom-User-Model-Proxy-Model/core/__init__.py -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/core/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/Custom-User-Model-Proxy-Model/core/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/core/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/Custom-User-Model-Proxy-Model/core/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/core/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/Custom-User-Model-Proxy-Model/core/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/core/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for core 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.0/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', 'core.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/core/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for core project. 3 | 4 | Generated by 'django-admin startproject' using Django 4.0.6. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/4.0/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/4.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-(9yt28f(r(4o^p8n!ts^grj$ic&^2l2yw*67d!3=rjhte=4bzb' 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 | 'user' 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 = 'core.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 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 = 'core.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': BASE_DIR / 'db.sqlite3', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_TZ = True 114 | 115 | 116 | # Static files (CSS, JavaScript, Images) 117 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ 118 | 119 | STATIC_URL = 'static/' 120 | 121 | # Default primary key field type 122 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 123 | 124 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 125 | -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/core/urls.py: -------------------------------------------------------------------------------- 1 | """core URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/4.0/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 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | ] 22 | -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/core/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for core 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.0/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', 'core.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/Custom-User-Model-Proxy-Model/db.sqlite3 -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/manage.py: -------------------------------------------------------------------------------- 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', 'core.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() 23 | -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/Custom-User-Model-Proxy-Model/user/__init__.py -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/Custom-User-Model-Proxy-Model/user/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/Custom-User-Model-Proxy-Model/user/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/Custom-User-Model-Proxy-Model/user/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/Custom-User-Model-Proxy-Model/user/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | from django.contrib.auth import get_user_model 3 | 4 | 5 | class UserConfig(AppConfig): 6 | default_auto_field = 'django.db.models.BigAutoField' 7 | name = 'user' 8 | 9 | def sayhi(self): 10 | print("hiya") 11 | 12 | def ready(self): 13 | User = get_user_model() 14 | User.sayhi = self.sayhi -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/fixtures/db_admin_fixture.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "auth.user", 4 | "pk": 1, 5 | "fields": { 6 | "username": "admin", 7 | "password": "pbkdf2_sha256$260000$KfZ2hspAeA8KhAAJ8mKpjw$60ajS7y4Fw72yg+DzZQADfUsUs4l3MJuhABupfjQ3z0=", 8 | "email": "a@a.com", 9 | "is_superuser": true, 10 | "is_staff": true, 11 | "is_active": true 12 | } 13 | }, 14 | { 15 | "model": "auth.user", 16 | "pk": 2, 17 | "fields": { 18 | "username": "student1", 19 | "password": "pbkdf2_sha256$260000$KfZ2hspAeA8KhAAJ8mKpjw$60ajS7y4Fw72yg+DzZQADfUsUs4l3MJuhABupfjQ3z0=", 20 | "email": "1@1.com", 21 | "first_name": "astudent", 22 | "is_active": true 23 | } 24 | }, 25 | { 26 | "model": "auth.user", 27 | "pk": 3, 28 | "fields": { 29 | "username": "student2", 30 | "password": "pbkdf2_sha256$260000$KfZ2hspAeA8KhAAJ8mKpjw$60ajS7y4Fw72yg+DzZQADfUsUs4l3MJuhABupfjQ3z0=", 31 | "email": "2@2.com", 32 | "first_name": "cstudent", 33 | "is_active": true 34 | } 35 | }, 36 | { 37 | "model": "auth.user", 38 | "pk": 4, 39 | "fields": { 40 | "username": "student3", 41 | "password": "pbkdf2_sha256$260000$KfZ2hspAeA8KhAAJ8mKpjw$60ajS7y4Fw72yg+DzZQADfUsUs4l3MJuhABupfjQ3z0=", 42 | "email": "3@3.com", 43 | "first_name": "bstudent", 44 | "is_active": true 45 | } 46 | }, 47 | { 48 | "model": "auth.user", 49 | "pk": 5, 50 | "fields": { 51 | "username": "student4", 52 | "password": "pbkdf2_sha256$260000$KfZ2hspAeA8KhAAJ8mKpjw$60ajS7y4Fw72yg+DzZQADfUsUs4l3MJuhABupfjQ3z0=", 53 | "email": "4@4.com", 54 | "first_name": "dstudent", 55 | "is_active": false 56 | } 57 | } 58 | ] 59 | -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.6 on 2022-07-11 11:30 2 | 3 | import django.contrib.auth.models 4 | from django.db import migrations 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | initial = True 10 | 11 | dependencies = [ 12 | ('auth', '0012_alter_user_first_name_max_length'), 13 | ] 14 | 15 | operations = [ 16 | migrations.CreateModel( 17 | name='Person', 18 | fields=[ 19 | ], 20 | options={ 21 | 'proxy': True, 22 | 'indexes': [], 23 | 'constraints': [], 24 | }, 25 | bases=('auth.user',), 26 | managers=[ 27 | ('objects', django.contrib.auth.models.UserManager()), 28 | ], 29 | ), 30 | ] 31 | -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/Custom-User-Model-Proxy-Model/user/migrations/__init__.py -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/Custom-User-Model-Proxy-Model/user/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/Custom-User-Model-Proxy-Model/user/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.admin import User 3 | 4 | class PersonManagerInactive(models.Manager): 5 | def get_queryset(self): 6 | return super(PersonManagerInactive, self).get_queryset().filter(is_active=False) 7 | 8 | class PersonManagerActive(models.Manager): 9 | def get_queryset(self): 10 | return super(PersonManagerActive, self).get_queryset().filter(is_active=True) 11 | 12 | class Person(User): 13 | 14 | inactive = PersonManagerInactive() 15 | active = PersonManagerActive() 16 | 17 | class Meta: 18 | proxy = True 19 | ordering = ('first_name',) 20 | 21 | @classmethod 22 | def count_all(cls,): 23 | return cls.objects.filter(is_active=True).count() 24 | 25 | def check_active(self): 26 | if self.is_active == True: 27 | return "You are Active!" 28 | else: 29 | return "You are not Active!" 30 | 31 | def __str__(self): 32 | return self.first_name 33 | 34 | -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Custom-User-Model-Proxy-Model/user/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Zander 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /case-study-1-query-1/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/db.sqlite3 -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/__init__.py -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for ecommerce 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.0/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', 'ecommerce.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/inventory/__init__.py -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/inventory/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/inventory/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/inventory/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/inventory/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/inventory/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/__pycache__/views.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/inventory/__pycache__/views.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import ( 3 | Attribute, 4 | AttributeValue, 5 | Category, 6 | Image, 7 | Inventory, 8 | Product, 9 | StockControl, 10 | ) 11 | 12 | # admin.site.register(Category) 13 | # admin.site.register(Attribute) 14 | # admin.site.register(AttributeValue) 15 | # admin.site.register(Image) 16 | # admin.site.register(Inventory) 17 | # admin.site.register(Product) 18 | # admin.site.register(StockControl) 19 | 20 | class ProductImageInline(admin.TabularInline): 21 | model = Image 22 | 23 | class AttributeValueInline(admin.TabularInline): 24 | model = AttributeValue 25 | 26 | class StockControlInline(admin.TabularInline): 27 | model = StockControl 28 | 29 | @admin.register(Inventory) 30 | class ProductInventoryAdmin(admin.ModelAdmin): 31 | inlines = [ProductImageInline, StockControlInline] 32 | 33 | @admin.register(Attribute) 34 | class ProductAdmin(admin.ModelAdmin): 35 | inlines = [ 36 | AttributeValueInline, 37 | ] 38 | 39 | @admin.register(Category) 40 | class CategoryAdmin(admin.ModelAdmin): 41 | prepopulated_fields = { 42 | "slug": ("name",), 43 | } 44 | 45 | @admin.register(Product) 46 | class ProductAdmin(admin.ModelAdmin): 47 | prepopulated_fields = { 48 | "slug": ("name",), 49 | } -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class InventoryConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'ecommerce.inventory' 7 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/fixtures/db_admin_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "auth.user", 4 | "pk": 1, 5 | "fields": { 6 | "username": "admin", 7 | "password": "pbkdf2_sha256$260000$KfZ2hspAeA8KhAAJ8mKpjw$60ajS7y4Fw72yg+DzZQADfUsUs4l3MJuhABupfjQ3z0=", 8 | "email": "a@a.com", 9 | "is_superuser": true, 10 | "is_staff": true, 11 | "is_active": true 12 | } 13 | } 14 | ] 15 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/fixtures/db_attribute_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "inventory.attribute", 4 | "id": "1", 5 | "fields": { 6 | "name": "woman-shoe-size", 7 | "description": "woman shoe size" 8 | } 9 | }, 10 | { 11 | "model": "inventory.attribute", 12 | "id": "2", 13 | "fields": { 14 | "name": "color", 15 | "description": "color" 16 | } 17 | }, 18 | { 19 | "model": "inventory.attribute", 20 | "id": "3", 21 | "fields": { 22 | "name": "man-shoe-size", 23 | "description": "men shoe size" 24 | } 25 | }, 26 | { 27 | "model": "inventory.attribute", 28 | "id": "4", 29 | "fields": { 30 | "name": "shoe-type", 31 | "description": "type of shoe" 32 | } 33 | } 34 | ] 35 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/fixtures/db_attribute_value_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "inventory.attributevalue", 4 | "id": "1", 5 | "fields": { 6 | "attribute": "1", 7 | "value": "5" 8 | } 9 | }, 10 | { 11 | "model": "inventory.attributevalue", 12 | "id": "2", 13 | "fields": { 14 | "attribute": "1", 15 | "value": "6" 16 | } 17 | }, 18 | { 19 | "model": "inventory.attributevalue", 20 | "id": "3", 21 | "fields": { 22 | "attribute": "2", 23 | "value": "red" 24 | } 25 | }, 26 | { 27 | "model": "inventory.attributevalue", 28 | "id": "4", 29 | "fields": { 30 | "attribute": "2", 31 | "value": "blue" 32 | } 33 | } 34 | ] 35 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/fixtures/db_attribute_values_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "inventory.inventory_attribute_values", 4 | "id": "1", 5 | "fields": { 6 | "attributevalue_id": "1", 7 | "inventory_id": "1" 8 | } 9 | }, 10 | { 11 | "model": "inventory.inventory_attribute_values", 12 | "id": "2", 13 | "fields": { 14 | "attributevalue_id": "1", 15 | "inventory_id": "2" 16 | } 17 | }, 18 | { 19 | "model": "inventory.inventory_attribute_values", 20 | "id": "3", 21 | "fields": { 22 | "attributevalue_id": "1", 23 | "inventory_id": "3" 24 | } 25 | }, 26 | { 27 | "model": "inventory.inventory_attribute_values", 28 | "id": "4", 29 | "fields": { 30 | "attributevalue_id": "1", 31 | "inventory_id": "4" 32 | } 33 | }, 34 | { 35 | "model": "inventory.inventory_attribute_values", 36 | "id": "5", 37 | "fields": { 38 | "attributevalue_id": "1", 39 | "inventory_id": "5" 40 | } 41 | }, 42 | { 43 | "model": "inventory.inventory_attribute_values", 44 | "id": "6", 45 | "fields": { 46 | "attributevalue_id": "1", 47 | "inventory_id": "6" 48 | } 49 | }, 50 | { 51 | "model": "inventory.inventory_attribute_values", 52 | "id": "7", 53 | "fields": { 54 | "attributevalue_id": "1", 55 | "inventory_id": "7" 56 | } 57 | }, 58 | { 59 | "model": "inventory.inventory_attribute_values", 60 | "id": "8", 61 | "fields": { 62 | "attributevalue_id": "1", 63 | "inventory_id": "8" 64 | } 65 | }, 66 | { 67 | "model": "inventory.inventory_attribute_values", 68 | "id": "9", 69 | "fields": { 70 | "attributevalue_id": "1", 71 | "inventory_id": "9" 72 | } 73 | }, 74 | { 75 | "model": "inventory.inventory_attribute_values", 76 | "id": "10", 77 | "fields": { 78 | "attributevalue_id": "1", 79 | "inventory_id": "10" 80 | } 81 | }, 82 | { 83 | "model": "inventory.inventory_attribute_values", 84 | "id": "11", 85 | "fields": { 86 | "attributevalue_id": "1", 87 | "inventory_id": "11" 88 | } 89 | }, 90 | { 91 | "model": "inventory.inventory_attribute_values", 92 | "id": "12", 93 | "fields": { 94 | "attributevalue_id": "1", 95 | "inventory_id": "12" 96 | } 97 | }, 98 | { 99 | "model": "inventory.inventory_attribute_values", 100 | "id": "13", 101 | "fields": { 102 | "attributevalue_id": "1", 103 | "inventory_id": "13" 104 | } 105 | }, 106 | { 107 | "model": "inventory.inventory_attribute_values", 108 | "id": "14", 109 | "fields": { 110 | "attributevalue_id": "1", 111 | "inventory_id": "14" 112 | } 113 | }, 114 | { 115 | "model": "inventory.inventory_attribute_values", 116 | "id": "15", 117 | "fields": { 118 | "attributevalue_id": "1", 119 | "inventory_id": "15" 120 | } 121 | }, 122 | { 123 | "model": "inventory.inventory_attribute_values", 124 | "id": "16", 125 | "fields": { 126 | "attributevalue_id": "1", 127 | "inventory_id": "16" 128 | } 129 | }, 130 | { 131 | "model": "inventory.inventory_attribute_values", 132 | "id": "17", 133 | "fields": { 134 | "attributevalue_id": "1", 135 | "inventory_id": "17" 136 | } 137 | }, 138 | { 139 | "model": "inventory.inventory_attribute_values", 140 | "id": "18", 141 | "fields": { 142 | "attributevalue_id": "1", 143 | "inventory_id": "18" 144 | } 145 | }, 146 | { 147 | "model": "inventory.inventory_attribute_values", 148 | "id": "19", 149 | "fields": { 150 | "attributevalue_id": "1", 151 | "inventory_id": "19" 152 | } 153 | }, 154 | { 155 | "model": "inventory.inventory_attribute_values", 156 | "id": "20", 157 | "fields": { 158 | "attributevalue_id": "1", 159 | "inventory_id": "20" 160 | } 161 | }, 162 | { 163 | "model": "inventory.inventory_attribute_values", 164 | "id": "21", 165 | "fields": { 166 | "attributevalue_id": "1", 167 | "inventory_id": "21" 168 | } 169 | }, 170 | { 171 | "model": "inventory.inventory_attribute_values", 172 | "id": "22", 173 | "fields": { 174 | "attributevalue_id": "1", 175 | "inventory_id": "22" 176 | } 177 | }, 178 | { 179 | "model": "inventory.inventory_attribute_values", 180 | "id": "23", 181 | "fields": { 182 | "attributevalue_id": "1", 183 | "inventory_id": "23" 184 | } 185 | }, 186 | { 187 | "model": "inventory.inventory_attribute_values", 188 | "id": "24", 189 | "fields": { 190 | "attributevalue_id": "1", 191 | "inventory_id": "24" 192 | } 193 | }, 194 | { 195 | "model": "inventory.inventory_attribute_values", 196 | "id": "25", 197 | "fields": { 198 | "attributevalue_id": "1", 199 | "inventory_id": "25" 200 | } 201 | }, 202 | { 203 | "model": "inventory.inventory_attribute_values", 204 | "id": "26", 205 | "fields": { 206 | "attributevalue_id": "1", 207 | "inventory_id": "26" 208 | } 209 | }, 210 | { 211 | "model": "inventory.inventory_attribute_values", 212 | "id": "27", 213 | "fields": { 214 | "attributevalue_id": "1", 215 | "inventory_id": "27" 216 | } 217 | }, 218 | { 219 | "model": "inventory.inventory_attribute_values", 220 | "id": "28", 221 | "fields": { 222 | "attributevalue_id": "1", 223 | "inventory_id": "28" 224 | } 225 | }, 226 | { 227 | "model": "inventory.inventory_attribute_values", 228 | "id": "29", 229 | "fields": { 230 | "attributevalue_id": "1", 231 | "inventory_id": "29" 232 | } 233 | }, 234 | { 235 | "model": "inventory.inventory_attribute_values", 236 | "id": "30", 237 | "fields": { 238 | "attributevalue_id": "1", 239 | "inventory_id": "30" 240 | } 241 | }, 242 | { 243 | "model": "inventory.inventory_attribute_values", 244 | "id": "31", 245 | "fields": { 246 | "attributevalue_id": "1", 247 | "inventory_id": "31" 248 | } 249 | }, 250 | { 251 | "model": "inventory.inventory_attribute_values", 252 | "id": "32", 253 | "fields": { 254 | "attributevalue_id": "1", 255 | "inventory_id": "32" 256 | } 257 | }, 258 | { 259 | "model": "inventory.inventory_attribute_values", 260 | "id": "33", 261 | "fields": { 262 | "attributevalue_id": "1", 263 | "inventory_id": "33" 264 | } 265 | }, 266 | { 267 | "model": "inventory.inventory_attribute_values", 268 | "id": "34", 269 | "fields": { 270 | "attributevalue_id": "1", 271 | "inventory_id": "34" 272 | } 273 | }, 274 | { 275 | "model": "inventory.inventory_attribute_values", 276 | "id": "35", 277 | "fields": { 278 | "attributevalue_id": "1", 279 | "inventory_id": "35" 280 | } 281 | }, 282 | { 283 | "model": "inventory.inventory_attribute_values", 284 | "id": "36", 285 | "fields": { 286 | "attributevalue_id": "1", 287 | "inventory_id": "36" 288 | } 289 | }, 290 | { 291 | "model": "inventory.inventory_attribute_values", 292 | "id": "37", 293 | "fields": { 294 | "attributevalue_id": "1", 295 | "inventory_id": "37" 296 | } 297 | }, 298 | { 299 | "model": "inventory.inventory_attribute_values", 300 | "id": "38", 301 | "fields": { 302 | "attributevalue_id": "1", 303 | "inventory_id": "38" 304 | } 305 | }, 306 | { 307 | "model": "inventory.inventory_attribute_values", 308 | "id": "39", 309 | "fields": { 310 | "attributevalue_id": "1", 311 | "inventory_id": "39" 312 | } 313 | }, 314 | { 315 | "model": "inventory.inventory_attribute_values", 316 | "id": "40", 317 | "fields": { 318 | "attributevalue_id": "1", 319 | "inventory_id": "40" 320 | } 321 | }, 322 | { 323 | "model": "inventory.inventory_attribute_values", 324 | "id": "41", 325 | "fields": { 326 | "attributevalue_id": "1", 327 | "inventory_id": "41" 328 | } 329 | }, 330 | { 331 | "model": "inventory.inventory_attribute_values", 332 | "id": "42", 333 | "fields": { 334 | "attributevalue_id": "1", 335 | "inventory_id": "42" 336 | } 337 | }, 338 | { 339 | "model": "inventory.inventory_attribute_values", 340 | "id": "43", 341 | "fields": { 342 | "attributevalue_id": "1", 343 | "inventory_id": "43" 344 | } 345 | }, 346 | { 347 | "model": "inventory.inventory_attribute_values", 348 | "id": "44", 349 | "fields": { 350 | "attributevalue_id": "1", 351 | "inventory_id": "44" 352 | } 353 | }, 354 | { 355 | "model": "inventory.inventory_attribute_values", 356 | "id": "45", 357 | "fields": { 358 | "attributevalue_id": "1", 359 | "inventory_id": "45" 360 | } 361 | }, 362 | { 363 | "model": "inventory.inventory_attribute_values", 364 | "id": "46", 365 | "fields": { 366 | "attributevalue_id": "1", 367 | "inventory_id": "46" 368 | } 369 | }, 370 | { 371 | "model": "inventory.inventory_attribute_values", 372 | "id": "47", 373 | "fields": { 374 | "attributevalue_id": "1", 375 | "inventory_id": "47" 376 | } 377 | }, 378 | { 379 | "model": "inventory.inventory_attribute_values", 380 | "id": "48", 381 | "fields": { 382 | "attributevalue_id": "1", 383 | "inventory_id": "48" 384 | } 385 | }, 386 | { 387 | "model": "inventory.inventory_attribute_values", 388 | "id": "49", 389 | "fields": { 390 | "attributevalue_id": "1", 391 | "inventory_id": "49" 392 | } 393 | } 394 | ] 395 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/fixtures/db_category_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "inventory.category", 4 | "pk": 1, 5 | "fields": { 6 | "name": "fashion", 7 | "slug": "fashion", 8 | "is_active": true 9 | } 10 | }, 11 | { 12 | "model": "inventory.category", 13 | "pk": 2, 14 | "fields": { 15 | "name": "woman", 16 | "slug": "woman", 17 | "is_active": true 18 | } 19 | }, 20 | { 21 | "model": "inventory.category", 22 | "pk": 3, 23 | "fields": { 24 | "name": "shoes", 25 | "slug": "shoes", 26 | "is_active": true 27 | } 28 | }, 29 | { 30 | "model": "inventory.category", 31 | "pk": 4, 32 | "fields": { 33 | "name": "sport and fitness", 34 | "slug": "sport-and-fitness", 35 | "is_active": true 36 | } 37 | }, 38 | { 39 | "model": "inventory.category", 40 | "pk": 5, 41 | "fields": { 42 | "name": "general purpose", 43 | "slug": "general-purpose", 44 | "is_active": true 45 | } 46 | }, 47 | { 48 | "model": "inventory.category", 49 | "pk": 6, 50 | "fields": { 51 | "name": "flats", 52 | "slug": "flats", 53 | "is_active": true 54 | } 55 | }, 56 | { 57 | "model": "inventory.category", 58 | "pk": 7, 59 | "fields": { 60 | "name": "casual", 61 | "slug": "casual", 62 | "is_active": true 63 | } 64 | }, 65 | { 66 | "model": "inventory.category", 67 | "pk": 8, 68 | "fields": { 69 | "name": "boots", 70 | "slug": "boots", 71 | "is_active": true 72 | } 73 | }, 74 | { 75 | "model": "inventory.category", 76 | "pk": 9, 77 | "fields": { 78 | "name": "heels", 79 | "slug": "heels", 80 | "is_active": true 81 | } 82 | }, 83 | { 84 | "model": "inventory.category", 85 | "pk": 10, 86 | "fields": { 87 | "name": "wedges", 88 | "slug": "wedges", 89 | "is_active": true 90 | } 91 | }, 92 | { 93 | "model": "inventory.category", 94 | "pk": 11, 95 | "fields": { 96 | "name": "booties", 97 | "slug": "booties", 98 | "is_active": true 99 | } 100 | }, 101 | { 102 | "model": "inventory.category", 103 | "pk": 12, 104 | "fields": { 105 | "name": "loafers", 106 | "slug": "loafers", 107 | "is_active": true 108 | } 109 | }, 110 | { 111 | "model": "inventory.category", 112 | "pk": 13, 113 | "fields": { 114 | "name": "sandalls", 115 | "slug": "sandalls", 116 | "is_active": true 117 | } 118 | }, 119 | { 120 | "model": "inventory.category", 121 | "pk": 14, 122 | "fields": { 123 | "name": "slip-ons", 124 | "slug": "slip-ons", 125 | "is_active": true 126 | } 127 | }, 128 | { 129 | "model": "inventory.category", 130 | "pk": 15, 131 | "fields": { 132 | "name": "oxfords", 133 | "slug": "oxfords", 134 | "is_active": true 135 | } 136 | }, 137 | { 138 | "model": "inventory.category", 139 | "pk": 16, 140 | "fields": { 141 | "name": "slippers", 142 | "slug": "slippers", 143 | "is_active": true 144 | } 145 | }, 146 | { 147 | "model": "inventory.category", 148 | "pk": 17, 149 | "fields": { 150 | "name": "golf", 151 | "slug": "golf", 152 | "is_active": true 153 | } 154 | }, 155 | { 156 | "model": "inventory.category", 157 | "pk": 18, 158 | "fields": { 159 | "name": "trainers", 160 | "slug": "trainers", 161 | "is_active": true 162 | } 163 | }, 164 | { 165 | "model": "inventory.category", 166 | "pk": 19, 167 | "fields": { 168 | "name": "running", 169 | "slug": "running", 170 | "is_active": true 171 | } 172 | }, 173 | { 174 | "model": "inventory.category", 175 | "pk": 20, 176 | "fields": { 177 | "name": "pumps", 178 | "slug": "pumps", 179 | "is_active": true 180 | } 181 | }, 182 | { 183 | "model": "inventory.category", 184 | "pk": 21, 185 | "fields": { 186 | "name": "patio", 187 | "slug": "patio", 188 | "is_active": true 189 | } 190 | }, 191 | { 192 | "model": "inventory.category", 193 | "pk": 22, 194 | "fields": { 195 | "name": "designer", 196 | "slug": "designer", 197 | "is_active": true 198 | } 199 | }, 200 | { 201 | "model": "inventory.category", 202 | "pk": 23, 203 | "fields": { 204 | "name": "contemporary", 205 | "slug": "contemporary", 206 | "is_active": true 207 | } 208 | }, 209 | { 210 | "model": "inventory.category", 211 | "pk": 24, 212 | "fields": { 213 | "name": "comfort", 214 | "slug": "comfort", 215 | "is_active": true 216 | } 217 | }, 218 | { 219 | "model": "inventory.category", 220 | "pk": 25, 221 | "fields": { 222 | "name": "cross-training", 223 | "slug": "cross-training", 224 | "is_active": true 225 | } 226 | }, 227 | { 228 | "model": "inventory.category", 229 | "pk": 26, 230 | "fields": { 231 | "name": "formal", 232 | "slug": "formal", 233 | "is_active": true 234 | } 235 | }, 236 | { 237 | "model": "inventory.category", 238 | "pk": 27, 239 | "fields": { 240 | "name": "safety", 241 | "slug": "safety", 242 | "is_active": true 243 | } 244 | }, 245 | { 246 | "model": "inventory.category", 247 | "pk": 28, 248 | "fields": { 249 | "name": "hiking", 250 | "slug": "hiking", 251 | "is_active": true 252 | } 253 | }, 254 | { 255 | "model": "inventory.category", 256 | "pk": 29, 257 | "fields": { 258 | "name": "eco-friendly", 259 | "slug": "eco-friendly", 260 | "is_active": true 261 | } 262 | }, 263 | { 264 | "model": "inventory.category", 265 | "pk": 30, 266 | "fields": { 267 | "name": "cycling", 268 | "slug": "cycling", 269 | "is_active": true 270 | } 271 | }, 272 | { 273 | "model": "inventory.category", 274 | "pk": 31, 275 | "fields": { 276 | "name": "moccasins", 277 | "slug": "moccasins", 278 | "is_active": true 279 | } 280 | }, 281 | { 282 | "model": "inventory.category", 283 | "pk": 32, 284 | "fields": { 285 | "name": "kids", 286 | "slug": "kids", 287 | "is_active": true 288 | } 289 | }, 290 | { 291 | "model": "inventory.category", 292 | "pk": 33, 293 | "fields": { 294 | "name": "halloween", 295 | "slug": "halloween", 296 | "is_active": true 297 | } 298 | }, 299 | { 300 | "model": "inventory.category", 301 | "pk": 34, 302 | "fields": { 303 | "name": "winter", 304 | "slug": "winter", 305 | "is_active": true 306 | } 307 | }, 308 | { 309 | "model": "inventory.category", 310 | "pk": 35, 311 | "fields": { 312 | "name": "baseball", 313 | "slug": "baseball", 314 | "is_active": true 315 | } 316 | } 317 | ] 318 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/fixtures/db_product_category_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "inventory.product_category", 4 | "id": "1", 5 | "fields": { 6 | "product_id": "1", 7 | "category_id": "1" 8 | } 9 | }, 10 | { 11 | "model": "inventory.product_category", 12 | "id": "2", 13 | "fields": { 14 | "product_id": "2", 15 | "category_id": "2" 16 | } 17 | }, 18 | { 19 | "model": "inventory.product_category", 20 | "id": "3", 21 | "fields": { 22 | "product_id": "3", 23 | "category_id": "3" 24 | } 25 | }, 26 | { 27 | "model": "inventory.product_category", 28 | "id": "4", 29 | "fields": { 30 | "product_id": "4", 31 | "category_id": "4" 32 | } 33 | }, 34 | { 35 | "model": "inventory.product_category", 36 | "id": "5", 37 | "fields": { 38 | "product_id": "5", 39 | "category_id": "5" 40 | } 41 | }, 42 | { 43 | "model": "inventory.product_category", 44 | "id": "6", 45 | "fields": { 46 | "product_id": "6", 47 | "category_id": "6" 48 | } 49 | }, 50 | { 51 | "model": "inventory.product_category", 52 | "id": "7", 53 | "fields": { 54 | "product_id": "7", 55 | "category_id": "7" 56 | } 57 | }, 58 | { 59 | "model": "inventory.product_category", 60 | "id": "8", 61 | "fields": { 62 | "product_id": "8", 63 | "category_id": "8" 64 | } 65 | }, 66 | 67 | { 68 | "model": "inventory.product_category", 69 | "id": "9", 70 | "fields": { 71 | "product_id": "9", 72 | "category_id": "1" 73 | } 74 | }, 75 | { 76 | "model": "inventory.product_category", 77 | "id": "10", 78 | "fields": { 79 | "product_id": "10", 80 | "category_id": "2" 81 | } 82 | }, 83 | { 84 | "model": "inventory.product_category", 85 | "id": "11", 86 | "fields": { 87 | "product_id": "11", 88 | "category_id": "3" 89 | } 90 | }, 91 | { 92 | "model": "inventory.product_category", 93 | "id": "12", 94 | "fields": { 95 | "product_id": "12", 96 | "category_id": "4" 97 | } 98 | }, 99 | 100 | { 101 | "model": "inventory.product_category", 102 | "id": "13", 103 | "fields": { 104 | "product_id": "13", 105 | "category_id": "5" 106 | } 107 | }, 108 | { 109 | "model": "inventory.product_category", 110 | "id": "14", 111 | "fields": { 112 | "product_id": "14", 113 | "category_id": "6" 114 | } 115 | }, 116 | { 117 | "model": "inventory.product_category", 118 | "id": "15", 119 | "fields": { 120 | "product_id": "15", 121 | "category_id": "7" 122 | } 123 | }, 124 | { 125 | "model": "inventory.product_category", 126 | "id": "16", 127 | "fields": { 128 | "product_id": "16", 129 | "category_id": "8" 130 | } 131 | }, 132 | 133 | { 134 | "model": "inventory.product_category", 135 | "id": "17", 136 | "fields": { 137 | "product_id": "1", 138 | "category_id": "9" 139 | } 140 | }, 141 | { 142 | "model": "inventory.product_category", 143 | "id": "17", 144 | "fields": { 145 | "product_id": "2", 146 | "category_id": "1" 147 | } 148 | }, 149 | { 150 | "model": "inventory.product_category", 151 | "id": "18", 152 | "fields": { 153 | "product_id": "18", 154 | "category_id": "2" 155 | } 156 | }, 157 | { 158 | "model": "inventory.product_category", 159 | "id": "19", 160 | "fields": { 161 | "product_id": "19", 162 | "category_id": "3" 163 | } 164 | }, 165 | { 166 | "model": "inventory.product_category", 167 | "id": "20", 168 | "fields": { 169 | "product_id": "20", 170 | "category_id": "4" 171 | } 172 | }, 173 | { 174 | "model": "inventory.product_category", 175 | "id": "21", 176 | "fields": { 177 | "product_id": "21", 178 | "category_id": "5" 179 | } 180 | }, 181 | { 182 | "model": "inventory.product_category", 183 | "id": "22", 184 | "fields": { 185 | "product_id": "22", 186 | "category_id": "6" 187 | } 188 | }, 189 | { 190 | "model": "inventory.product_category", 191 | "id": "23", 192 | "fields": { 193 | "product_id": "23", 194 | "category_id": "7" 195 | } 196 | }, 197 | { 198 | "model": "inventory.product_category", 199 | "id": "24", 200 | "fields": { 201 | "product_id": "24", 202 | "category_id": "8" 203 | } 204 | }, 205 | { 206 | "model": "inventory.product_category", 207 | "id": "25", 208 | "fields": { 209 | "product_id": "25", 210 | "category_id": "9" 211 | } 212 | }, 213 | { 214 | "model": "inventory.product_category", 215 | "id": "26", 216 | "fields": { 217 | "product_id": "26", 218 | "category_id": "3" 219 | } 220 | }, 221 | { 222 | "model": "inventory.product_category", 223 | "id": "27", 224 | "fields": { 225 | "product_id": "27", 226 | "category_id": "4" 227 | } 228 | }, 229 | { 230 | "model": "inventory.product_category", 231 | "id": "28", 232 | "fields": { 233 | "product_id": "28", 234 | "category_id": "1" 235 | } 236 | }, 237 | { 238 | "model": "inventory.product_category", 239 | "id": "29", 240 | "fields": { 241 | "product_id": "29", 242 | "category_id": "2" 243 | } 244 | }, 245 | { 246 | "model": "inventory.product_category", 247 | "id": "30", 248 | "fields": { 249 | "product_id": "30", 250 | "category_id": "3" 251 | } 252 | }, 253 | { 254 | "model": "inventory.product_category", 255 | "id": "31", 256 | "fields": { 257 | "product_id": "31", 258 | "category_id": "4" 259 | } 260 | }, 261 | { 262 | "model": "inventory.product_category", 263 | "id": "32", 264 | "fields": { 265 | "product_id": "32", 266 | "category_id": "1" 267 | } 268 | }, 269 | { 270 | "model": "inventory.product_category", 271 | "id": "33", 272 | "fields": { 273 | "product_id": "33", 274 | "category_id": "2" 275 | } 276 | }, 277 | { 278 | "model": "inventory.product_category", 279 | "id": "34", 280 | "fields": { 281 | "product_id": "34", 282 | "category_id": "3" 283 | } 284 | }, 285 | { 286 | "model": "inventory.product_category", 287 | "id": "35", 288 | "fields": { 289 | "product_id": "35", 290 | "category_id": "4" 291 | } 292 | }, 293 | { 294 | "model": "inventory.product_category", 295 | "id": "36", 296 | "fields": { 297 | "product_id": "36", 298 | "category_id": "1" 299 | } 300 | }, 301 | { 302 | "model": "inventory.product_category", 303 | "id": "37", 304 | "fields": { 305 | "product_id": "37", 306 | "category_id": "2" 307 | } 308 | }, 309 | { 310 | "model": "inventory.product_category", 311 | "id": "38", 312 | "fields": { 313 | "product_id": "38", 314 | "category_id": "3" 315 | } 316 | }, 317 | { 318 | "model": "inventory.product_category", 319 | "id": "39", 320 | "fields": { 321 | "product_id": "39", 322 | "category_id": "4" 323 | } 324 | }, 325 | { 326 | "model": "inventory.product_category", 327 | "id": "40", 328 | "fields": { 329 | "product_id": "40", 330 | "category_id": "1" 331 | } 332 | }, 333 | { 334 | "model": "inventory.product_category", 335 | "id": "41", 336 | "fields": { 337 | "product_id": "41", 338 | "category_id": "2" 339 | } 340 | }, 341 | { 342 | "model": "inventory.product_category", 343 | "id": "42", 344 | "fields": { 345 | "product_id": "42", 346 | "category_id": "3" 347 | } 348 | }, 349 | { 350 | "model": "inventory.product_category", 351 | "id": "43", 352 | "fields": { 353 | "product_id": "43", 354 | "category_id": "4" 355 | } 356 | }, 357 | { 358 | "model": "inventory.product_category", 359 | "id": "44", 360 | "fields": { 361 | "product_id": "44", 362 | "category_id": "1" 363 | } 364 | }, 365 | { 366 | "model": "inventory.product_category", 367 | "id": "45", 368 | "fields": { 369 | "product_id": "45", 370 | "category_id": "2" 371 | } 372 | }, 373 | { 374 | "model": "inventory.product_category", 375 | "id": "46", 376 | "fields": { 377 | "product_id": "46", 378 | "category_id": "3" 379 | } 380 | }, 381 | { 382 | "model": "inventory.product_category", 383 | "id": "47", 384 | "fields": { 385 | "product_id": "47", 386 | "category_id": "4" 387 | } 388 | }, 389 | { 390 | "model": "inventory.product_category", 391 | "id": "48", 392 | "fields": { 393 | "product_id": "48", 394 | "category_id": "1" 395 | } 396 | }, 397 | { 398 | "model": "inventory.product_category", 399 | "id": "49", 400 | "fields": { 401 | "product_id": "49", 402 | "category_id": "2" 403 | } 404 | }, 405 | { 406 | "model": "inventory.product_category", 407 | "id": "50", 408 | "fields": { 409 | "product_id": "50", 410 | "category_id": "2" 411 | } 412 | } 413 | ] 414 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/fixtures/db_stock_control_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "inventory.stockcontrol", 4 | "id": "1", 5 | "fields": { 6 | "inventory": "1", 7 | "last_checked": "2021-09-01T13:20:30+03:00", 8 | "units": "135" 9 | } 10 | }, 11 | { 12 | "model": "inventory.stockcontrol", 13 | "id": "2", 14 | "fields": { 15 | "inventory": "2", 16 | "last_checked": "2021-09-01T13:20:30+03:00", 17 | "units": "188" 18 | } 19 | }, 20 | { 21 | "model": "inventory.stockcontrol", 22 | "id": "3", 23 | "fields": { 24 | "inventory": "3", 25 | "last_checked": "2021-09-01T13:20:30+03:00", 26 | "units": "2" 27 | } 28 | }, 29 | { 30 | "model": "inventory.stockcontrol", 31 | "id": "4", 32 | "fields": { 33 | "inventory": "4", 34 | "last_checked": "2021-09-01T13:20:30+03:00", 35 | "units": "153" 36 | } 37 | }, 38 | { 39 | "model": "inventory.stockcontrol", 40 | "id": "5", 41 | "fields": { 42 | "inventory": "5", 43 | "last_checked": "2021-09-01T13:20:30+03:00", 44 | "units": "84" 45 | } 46 | }, 47 | { 48 | "model": "inventory.stockcontrol", 49 | "id": "6", 50 | "fields": { 51 | "inventory": "6", 52 | "last_checked": "2021-09-01T13:20:30+03:00", 53 | "units": "92" 54 | } 55 | }, 56 | { 57 | "model": "inventory.stockcontrol", 58 | "id": "7", 59 | "fields": { 60 | "inventory": "7", 61 | "last_checked": "2021-09-01T13:20:30+03:00", 62 | "units": "153" 63 | } 64 | }, 65 | { 66 | "model": "inventory.stockcontrol", 67 | "id": "8", 68 | "fields": { 69 | "inventory": "8", 70 | "last_checked": "2021-09-01T13:20:30+03:00", 71 | "units": "153" 72 | } 73 | }, 74 | { 75 | "model": "inventory.stockcontrol", 76 | "id": "9", 77 | "fields": { 78 | "inventory": "9", 79 | "last_checked": "2021-09-01T13:20:30+03:00", 80 | "units": "113" 81 | } 82 | }, 83 | { 84 | "model": "inventory.stockcontrol", 85 | "id": "10", 86 | "fields": { 87 | "inventory": "10", 88 | "last_checked": "2021-09-01T13:20:30+03:00", 89 | "units": "77" 90 | } 91 | }, 92 | { 93 | "model": "inventory.stockcontrol", 94 | "id": "11", 95 | "fields": { 96 | "inventory": "11", 97 | "last_checked": "2021-09-01T13:20:30+03:00", 98 | "units": "181" 99 | } 100 | }, 101 | { 102 | "model": "inventory.stockcontrol", 103 | "id": "12", 104 | "fields": { 105 | "inventory": "12", 106 | "last_checked": "2021-09-01T13:20:30+03:00", 107 | "units": "178" 108 | } 109 | }, 110 | { 111 | "model": "inventory.stockcontrol", 112 | "id": "13", 113 | "fields": { 114 | "inventory": "13", 115 | "last_checked": "2021-09-01T13:20:30+03:00", 116 | "units": "43" 117 | } 118 | }, 119 | { 120 | "model": "inventory.stockcontrol", 121 | "id": "14", 122 | "fields": { 123 | "inventory": "14", 124 | "last_checked": "2021-09-01T13:20:30+03:00", 125 | "units": "18" 126 | } 127 | }, 128 | { 129 | "model": "inventory.stockcontrol", 130 | "id": "15", 131 | "fields": { 132 | "inventory": "15", 133 | "last_checked": "2021-09-01T13:20:30+03:00", 134 | "units": "53" 135 | } 136 | }, 137 | { 138 | "model": "inventory.stockcontrol", 139 | "id": "16", 140 | "fields": { 141 | "inventory": "16", 142 | "last_checked": "2021-09-01T13:20:30+03:00", 143 | "units": "83" 144 | } 145 | }, 146 | { 147 | "model": "inventory.stockcontrol", 148 | "id": "17", 149 | "fields": { 150 | "inventory": "17", 151 | "last_checked": "2021-09-01T13:20:30+03:00", 152 | "units": "102" 153 | } 154 | }, 155 | { 156 | "model": "inventory.stockcontrol", 157 | "id": "18", 158 | "fields": { 159 | "inventory": "18", 160 | "last_checked": "2021-09-01T13:20:30+03:00", 161 | "units": "133" 162 | } 163 | }, 164 | { 165 | "model": "inventory.stockcontrol", 166 | "id": "19", 167 | "fields": { 168 | "inventory": "19", 169 | "last_checked": "2021-09-01T13:20:30+03:00", 170 | "units": "20" 171 | } 172 | }, 173 | { 174 | "model": "inventory.stockcontrol", 175 | "id": "20", 176 | "fields": { 177 | "inventory": "20", 178 | "last_checked": "2021-09-01T13:20:30+03:00", 179 | "units": "172" 180 | } 181 | }, 182 | { 183 | "model": "inventory.stockcontrol", 184 | "id": "21", 185 | "fields": { 186 | "inventory": "21", 187 | "last_checked": "2021-09-01T13:20:30+03:00", 188 | "units": "116" 189 | } 190 | }, 191 | { 192 | "model": "inventory.stockcontrol", 193 | "id": "22", 194 | "fields": { 195 | "inventory": "22", 196 | "last_checked": "2021-09-01T13:20:30+03:00", 197 | "units": "3" 198 | } 199 | }, 200 | { 201 | "model": "inventory.stockcontrol", 202 | "id": "23", 203 | "fields": { 204 | "inventory": "23", 205 | "last_checked": "2021-09-01T13:20:30+03:00", 206 | "units": "5" 207 | } 208 | }, 209 | { 210 | "model": "inventory.stockcontrol", 211 | "id": "24", 212 | "fields": { 213 | "inventory": "24", 214 | "last_checked": "2021-09-01T13:20:30+03:00", 215 | "units": "5" 216 | } 217 | }, 218 | { 219 | "model": "inventory.stockcontrol", 220 | "id": "25", 221 | "fields": { 222 | "inventory": "25", 223 | "last_checked": "2021-09-01T13:20:30+03:00", 224 | "units": "140" 225 | } 226 | }, 227 | { 228 | "model": "inventory.stockcontrol", 229 | "id": "26", 230 | "fields": { 231 | "inventory": "26", 232 | "last_checked": "2021-09-01T13:20:30+03:00", 233 | "units": "63" 234 | } 235 | }, 236 | { 237 | "model": "inventory.stockcontrol", 238 | "id": "27", 239 | "fields": { 240 | "inventory": "27", 241 | "last_checked": "2021-09-01T13:20:30+03:00", 242 | "units": "51" 243 | } 244 | }, 245 | { 246 | "model": "inventory.stockcontrol", 247 | "id": "28", 248 | "fields": { 249 | "inventory": "28", 250 | "last_checked": "2021-09-01T13:20:30+03:00", 251 | "units": "46" 252 | } 253 | }, 254 | { 255 | "model": "inventory.stockcontrol", 256 | "id": "29", 257 | "fields": { 258 | "inventory": "29", 259 | "last_checked": "2021-09-01T13:20:30+03:00", 260 | "units": "158" 261 | } 262 | }, 263 | { 264 | "model": "inventory.stockcontrol", 265 | "id": "30", 266 | "fields": { 267 | "inventory": "30", 268 | "last_checked": "2021-09-01T13:20:30+03:00", 269 | "units": "95" 270 | } 271 | }, 272 | { 273 | "model": "inventory.stockcontrol", 274 | "id": "31", 275 | "fields": { 276 | "inventory": "31", 277 | "last_checked": "2021-09-01T13:20:30+03:00", 278 | "units": "134" 279 | } 280 | }, 281 | { 282 | "model": "inventory.stockcontrol", 283 | "id": "32", 284 | "fields": { 285 | "inventory": "32", 286 | "last_checked": "2021-09-01T13:20:30+03:00", 287 | "units": "110" 288 | } 289 | }, 290 | { 291 | "model": "inventory.stockcontrol", 292 | "id": "33", 293 | "fields": { 294 | "inventory": "33", 295 | "last_checked": "2021-09-01T13:20:30+03:00", 296 | "units": "21" 297 | } 298 | }, 299 | { 300 | "model": "inventory.stockcontrol", 301 | "id": "34", 302 | "fields": { 303 | "inventory": "34", 304 | "last_checked": "2021-09-01T13:20:30+03:00", 305 | "units": "164" 306 | } 307 | }, 308 | { 309 | "model": "inventory.stockcontrol", 310 | "id": "35", 311 | "fields": { 312 | "inventory": "35", 313 | "last_checked": "2021-09-01T13:20:30+03:00", 314 | "units": "1" 315 | } 316 | }, 317 | { 318 | "model": "inventory.stockcontrol", 319 | "id": "36", 320 | "fields": { 321 | "inventory": "36", 322 | "last_checked": "2021-09-01T13:20:30+03:00", 323 | "units": "37" 324 | } 325 | }, 326 | { 327 | "model": "inventory.stockcontrol", 328 | "id": "37", 329 | "fields": { 330 | "inventory": "37", 331 | "last_checked": "2021-09-01T13:20:30+03:00", 332 | "units": "137" 333 | } 334 | }, 335 | { 336 | "model": "inventory.stockcontrol", 337 | "id": "38", 338 | "fields": { 339 | "inventory": "38", 340 | "last_checked": "2021-09-01T13:20:30+03:00", 341 | "units": "88" 342 | } 343 | }, 344 | { 345 | "model": "inventory.stockcontrol", 346 | "id": "39", 347 | "fields": { 348 | "inventory": "39", 349 | "last_checked": "2021-09-01T13:20:30+03:00", 350 | "units": "145" 351 | } 352 | }, 353 | { 354 | "model": "inventory.stockcontrol", 355 | "id": "40", 356 | "fields": { 357 | "inventory": "40", 358 | "last_checked": "2021-09-01T13:20:30+03:00", 359 | "units": "181" 360 | } 361 | }, 362 | { 363 | "model": "inventory.stockcontrol", 364 | "id": "41", 365 | "fields": { 366 | "inventory": "41", 367 | "last_checked": "2021-09-01T13:20:30+03:00", 368 | "units": "113" 369 | } 370 | }, 371 | { 372 | "model": "inventory.stockcontrol", 373 | "id": "42", 374 | "fields": { 375 | "inventory": "42", 376 | "last_checked": "2021-09-01T13:20:30+03:00", 377 | "units": "102" 378 | } 379 | }, 380 | { 381 | "model": "inventory.stockcontrol", 382 | "id": "43", 383 | "fields": { 384 | "inventory": "43", 385 | "last_checked": "2021-09-01T13:20:30+03:00", 386 | "units": "161" 387 | } 388 | }, 389 | { 390 | "model": "inventory.stockcontrol", 391 | "id": "44", 392 | "fields": { 393 | "inventory": "44", 394 | "last_checked": "2021-09-01T13:20:30+03:00", 395 | "units": "71" 396 | } 397 | }, 398 | { 399 | "model": "inventory.stockcontrol", 400 | "id": "45", 401 | "fields": { 402 | "inventory": "45", 403 | "last_checked": "2021-09-01T13:20:30+03:00", 404 | "units": "180" 405 | } 406 | }, 407 | { 408 | "model": "inventory.stockcontrol", 409 | "id": "46", 410 | "fields": { 411 | "inventory": "46", 412 | "last_checked": "2021-09-01T13:20:30+03:00", 413 | "units": "128" 414 | } 415 | }, 416 | { 417 | "model": "inventory.stockcontrol", 418 | "id": "47", 419 | "fields": { 420 | "inventory": "47", 421 | "last_checked": "2021-09-01T13:20:30+03:00", 422 | "units": "12" 423 | } 424 | }, 425 | { 426 | "model": "inventory.stockcontrol", 427 | "id": "48", 428 | "fields": { 429 | "inventory": "48", 430 | "last_checked": "2021-09-01T13:20:30+03:00", 431 | "units": "66" 432 | } 433 | }, 434 | { 435 | "model": "inventory.stockcontrol", 436 | "id": "49", 437 | "fields": { 438 | "inventory": "49", 439 | "last_checked": "2021-09-01T13:20:30+03:00", 440 | "units": "115" 441 | } 442 | } 443 | ] 444 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/management/commands/__pycache__/load-fixtures.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/inventory/management/commands/__pycache__/load-fixtures.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/management/commands/load-fixtures.py: -------------------------------------------------------------------------------- 1 | from django.core.management import call_command 2 | from django.core.management.base import BaseCommand 3 | 4 | class Command(BaseCommand): 5 | def handle(self, *args, **kwargs): 6 | call_command("makemigrations") 7 | call_command("migrate") 8 | call_command("loaddata", "db_admin_fixture_50.json") 9 | call_command("loaddata", "db_category_fixture_50.json") 10 | call_command("loaddata", "db_product_fixture_50.json") 11 | call_command("loaddata", "db_product_category_fixture_50.json") 12 | call_command("loaddata", "db_attribute_fixture_50.json") 13 | call_command("loaddata", "db_attribute_value_fixture_50.json") 14 | call_command("loaddata", "db_inventory_fixture_50.json") 15 | call_command("loaddata", "db_attribute_values_fixture_50.json") 16 | call_command("loaddata", "db_image_fixture_50.json") 17 | call_command("loaddata", "db_stock_control_fixture_50.json") -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.6 on 2022-07-08 18:36 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | initial = True 10 | 11 | dependencies = [ 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Attribute', 17 | fields=[ 18 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 19 | ('name', models.CharField(max_length=50)), 20 | ('description', models.TextField()), 21 | ], 22 | ), 23 | migrations.CreateModel( 24 | name='AttributeValue', 25 | fields=[ 26 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 27 | ('value', models.CharField(max_length=50)), 28 | ('attribute', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attribute', to='inventory.attribute')), 29 | ], 30 | ), 31 | migrations.CreateModel( 32 | name='Category', 33 | fields=[ 34 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 35 | ('name', models.CharField(max_length=50)), 36 | ('slug', models.SlugField()), 37 | ('is_active', models.BooleanField()), 38 | ], 39 | options={ 40 | 'verbose_name_plural': 'Categories', 41 | }, 42 | ), 43 | migrations.CreateModel( 44 | name='Inventory', 45 | fields=[ 46 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 47 | ('is_active', models.BooleanField()), 48 | ('is_default', models.BooleanField()), 49 | ('price', models.DecimalField(decimal_places=2, max_digits=5)), 50 | ('created_at', models.DateTimeField(auto_now_add=True)), 51 | ('sku', models.CharField(max_length=20, unique=True)), 52 | ('attribute_values', models.ManyToManyField(to='inventory.attributevalue')), 53 | ], 54 | options={ 55 | 'verbose_name_plural': 'Inventory', 56 | }, 57 | ), 58 | migrations.CreateModel( 59 | name='StockControl', 60 | fields=[ 61 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 62 | ('last_checked', models.DateTimeField(editable=False)), 63 | ('units', models.IntegerField(default=0)), 64 | ('inventory', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='inventory.inventory')), 65 | ], 66 | options={ 67 | 'verbose_name_plural': 'Stock Control', 68 | }, 69 | ), 70 | migrations.CreateModel( 71 | name='Product', 72 | fields=[ 73 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 74 | ('name', models.CharField(max_length=50)), 75 | ('description', models.TextField()), 76 | ('slug', models.SlugField()), 77 | ('is_active', models.BooleanField()), 78 | ('category', models.ManyToManyField(to='inventory.category')), 79 | ], 80 | ), 81 | migrations.AddField( 82 | model_name='inventory', 83 | name='product', 84 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='product', to='inventory.product'), 85 | ), 86 | migrations.CreateModel( 87 | name='Image', 88 | fields=[ 89 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 90 | ('url', models.ImageField(upload_to=None)), 91 | ('alternative_text', models.CharField(max_length=50)), 92 | ('is_feature', models.BooleanField()), 93 | ('inventory', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='inventory.inventory')), 94 | ], 95 | ), 96 | ] 97 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/inventory/migrations/__init__.py -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/inventory/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1-query-1/ecommerce/inventory/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | class Category(models.Model): 5 | name = models.CharField(max_length=50) 6 | slug = models.SlugField() 7 | is_active = models.BooleanField() 8 | 9 | class Meta: 10 | verbose_name_plural = "Categories" 11 | 12 | def __str__(self): 13 | return self.name 14 | 15 | 16 | class Product(models.Model): 17 | name = models.CharField(max_length=50) 18 | description = models.TextField() 19 | slug = models.SlugField() 20 | is_active = models.BooleanField() 21 | 22 | category = models.ManyToManyField(Category) 23 | 24 | def __str__(self): 25 | return self.name 26 | 27 | 28 | class Attribute(models.Model): 29 | name = models.CharField(max_length=50) 30 | description = models.TextField() 31 | 32 | def __str__(self): 33 | return self.name 34 | 35 | 36 | class AttributeValue(models.Model): 37 | value = models.CharField(max_length=50) 38 | 39 | attribute = models.ForeignKey( 40 | Attribute, related_name="attribute", on_delete=models.CASCADE 41 | ) 42 | 43 | def __str__(self): 44 | return self.value 45 | # return f"{self.attribute.name}:{self.value}" 46 | 47 | 48 | class Inventory(models.Model): 49 | is_active = models.BooleanField() 50 | is_default = models.BooleanField() 51 | price = models.DecimalField( 52 | max_digits=5, 53 | decimal_places=2, 54 | ) 55 | created_at = models.DateTimeField(auto_now_add=True, editable=False) 56 | sku = models.CharField( 57 | max_length=20, 58 | unique=True, 59 | ) 60 | # sku = models.UUIDField(default=uuid.uuid4, editable=False) 61 | 62 | product = models.ForeignKey( 63 | Product, related_name="product", on_delete=models.CASCADE 64 | ) 65 | attribute_values = models.ManyToManyField(AttributeValue) 66 | 67 | class Meta: 68 | verbose_name_plural = "Inventory" 69 | 70 | def __str__(self): 71 | return self.product.name 72 | 73 | 74 | class StockControl(models.Model): 75 | last_checked = models.DateTimeField(auto_now_add=False, editable=False) 76 | units = models.IntegerField(default=0) 77 | 78 | inventory = models.OneToOneField(Inventory, on_delete=models.CASCADE) 79 | 80 | class Meta: 81 | verbose_name_plural = "Stock Control" 82 | 83 | 84 | class Image(models.Model): 85 | url = models.ImageField(upload_to=None) 86 | alternative_text = models.CharField(max_length=50) 87 | is_feature = models.BooleanField() 88 | inventory = models.ForeignKey(Inventory, on_delete=models.CASCADE) 89 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/templates/grid-output.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Album example · Bootstrap v5.2 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 73 | 74 | 75 | 76 | 77 | 78 |
79 | 97 | 107 |
108 | 109 |
110 | 111 |
112 |
113 | 114 |
115 | 116 | {% for product in page_obj %} 117 | 118 |
119 |
120 | PlaceholderThumbnail 121 |
122 |

{{product.name}}

123 |
124 |
125 | 126 | 127 |
128 | 9 mins 129 |
130 |
131 |
132 |
133 | 134 | {% endfor %} 135 | 136 |
137 | 138 | 155 | 156 |
157 |
158 | 159 |
160 | 161 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('ex1/', views.all_products) 6 | ] 7 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/inventory/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from .models import Product 3 | from django.core.paginator import Paginator 4 | 5 | def all_products(request): 6 | objs = Product.objects.all() 7 | 8 | paginator = Paginator(objs, 8) 9 | 10 | page_number = request.GET.get('page') 11 | page_obj = paginator.get_page(page_number) 12 | 13 | return render(request, 'grid-output.html', {'page_obj':page_obj}) 14 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for ecommerce project. 3 | 4 | Generated by 'django-admin startproject' using Django 4.0.6. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/4.0/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/4.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-(r+0e&@p5emt5+cy#sj_*t5svwlneme^(c9kk6cr*!qi&1opf+' 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 | 'ecommerce.inventory', 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 = 'ecommerce.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 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 = 'ecommerce.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': BASE_DIR / 'db.sqlite3', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_TZ = True 114 | 115 | 116 | # Static files (CSS, JavaScript, Images) 117 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ 118 | 119 | STATIC_URL = 'static/' 120 | 121 | STATICFILES_DIRS = [ 122 | BASE_DIR / "static", 123 | ] 124 | 125 | # Default primary key field type 126 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 127 | 128 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 129 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/urls.py: -------------------------------------------------------------------------------- 1 | 2 | from django.contrib import admin 3 | from django.urls import path, include 4 | 5 | urlpatterns = [ 6 | path('admin/', admin.site.urls), 7 | path('query/', include('ecommerce.inventory.urls')) 8 | ] 9 | -------------------------------------------------------------------------------- /case-study-1-query-1/ecommerce/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for ecommerce 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.0/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', 'ecommerce.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /case-study-1-query-1/manage.py: -------------------------------------------------------------------------------- 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', 'ecommerce.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() 23 | -------------------------------------------------------------------------------- /case-study-1-query-1/requirements.txt: -------------------------------------------------------------------------------- 1 | asgiref==3.5.2 2 | Django==4.0.6 3 | Pillow==9.2.0 4 | sqlparse==0.4.2 5 | -------------------------------------------------------------------------------- /case-study-1-query-1/static/assets/brand/bootstrap-logo-white.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /case-study-1-query-1/static/assets/brand/bootstrap-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /case-study-1/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/db.sqlite3 -------------------------------------------------------------------------------- /case-study-1/ecommerce/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/__init__.py -------------------------------------------------------------------------------- /case-study-1/ecommerce/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1/ecommerce/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1/ecommerce/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1/ecommerce/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1/ecommerce/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for ecommerce 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.0/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', 'ecommerce.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/inventory/__init__.py -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/inventory/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/inventory/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/inventory/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/inventory/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import ( 3 | Attribute, 4 | AttributeValue, 5 | Category, 6 | Image, 7 | Inventory, 8 | Product, 9 | StockControl, 10 | ) 11 | 12 | # admin.site.register(Category) 13 | # admin.site.register(Attribute) 14 | # admin.site.register(AttributeValue) 15 | # admin.site.register(Image) 16 | # admin.site.register(Inventory) 17 | # admin.site.register(Product) 18 | # admin.site.register(StockControl) 19 | 20 | class ProductImageInline(admin.TabularInline): 21 | model = Image 22 | 23 | class AttributeValueInline(admin.TabularInline): 24 | model = AttributeValue 25 | 26 | class StockControlInline(admin.TabularInline): 27 | model = StockControl 28 | 29 | @admin.register(Inventory) 30 | class ProductInventoryAdmin(admin.ModelAdmin): 31 | inlines = [ProductImageInline, StockControlInline] 32 | 33 | @admin.register(Attribute) 34 | class ProductAdmin(admin.ModelAdmin): 35 | inlines = [ 36 | AttributeValueInline, 37 | ] 38 | 39 | @admin.register(Category) 40 | class CategoryAdmin(admin.ModelAdmin): 41 | prepopulated_fields = { 42 | "slug": ("name",), 43 | } 44 | 45 | @admin.register(Product) 46 | class ProductAdmin(admin.ModelAdmin): 47 | prepopulated_fields = { 48 | "slug": ("name",), 49 | } -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class InventoryConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'ecommerce.inventory' 7 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/fixtures/db_admin_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "auth.user", 4 | "pk": 1, 5 | "fields": { 6 | "username": "admin", 7 | "password": "pbkdf2_sha256$260000$KfZ2hspAeA8KhAAJ8mKpjw$60ajS7y4Fw72yg+DzZQADfUsUs4l3MJuhABupfjQ3z0=", 8 | "email": "a@a.com", 9 | "is_superuser": true, 10 | "is_staff": true, 11 | "is_active": true 12 | } 13 | } 14 | ] 15 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/fixtures/db_attribute_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "inventory.attribute", 4 | "id": "1", 5 | "fields": { 6 | "name": "woman-shoe-size", 7 | "description": "woman shoe size" 8 | } 9 | }, 10 | { 11 | "model": "inventory.attribute", 12 | "id": "2", 13 | "fields": { 14 | "name": "color", 15 | "description": "color" 16 | } 17 | }, 18 | { 19 | "model": "inventory.attribute", 20 | "id": "3", 21 | "fields": { 22 | "name": "man-shoe-size", 23 | "description": "men shoe size" 24 | } 25 | }, 26 | { 27 | "model": "inventory.attribute", 28 | "id": "4", 29 | "fields": { 30 | "name": "shoe-type", 31 | "description": "type of shoe" 32 | } 33 | } 34 | ] 35 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/fixtures/db_attribute_value_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "inventory.attributevalue", 4 | "id": "1", 5 | "fields": { 6 | "attribute": "1", 7 | "value": "5" 8 | } 9 | }, 10 | { 11 | "model": "inventory.attributevalue", 12 | "id": "2", 13 | "fields": { 14 | "attribute": "1", 15 | "value": "6" 16 | } 17 | }, 18 | { 19 | "model": "inventory.attributevalue", 20 | "id": "3", 21 | "fields": { 22 | "attribute": "2", 23 | "value": "red" 24 | } 25 | }, 26 | { 27 | "model": "inventory.attributevalue", 28 | "id": "4", 29 | "fields": { 30 | "attribute": "2", 31 | "value": "blue" 32 | } 33 | } 34 | ] 35 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/fixtures/db_attribute_values_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "inventory.inventory_attribute_values", 4 | "id": "1", 5 | "fields": { 6 | "attributevalue_id": "1", 7 | "inventory_id": "1" 8 | } 9 | }, 10 | { 11 | "model": "inventory.inventory_attribute_values", 12 | "id": "2", 13 | "fields": { 14 | "attributevalue_id": "1", 15 | "inventory_id": "2" 16 | } 17 | }, 18 | { 19 | "model": "inventory.inventory_attribute_values", 20 | "id": "3", 21 | "fields": { 22 | "attributevalue_id": "1", 23 | "inventory_id": "3" 24 | } 25 | }, 26 | { 27 | "model": "inventory.inventory_attribute_values", 28 | "id": "4", 29 | "fields": { 30 | "attributevalue_id": "1", 31 | "inventory_id": "4" 32 | } 33 | }, 34 | { 35 | "model": "inventory.inventory_attribute_values", 36 | "id": "5", 37 | "fields": { 38 | "attributevalue_id": "1", 39 | "inventory_id": "5" 40 | } 41 | }, 42 | { 43 | "model": "inventory.inventory_attribute_values", 44 | "id": "6", 45 | "fields": { 46 | "attributevalue_id": "1", 47 | "inventory_id": "6" 48 | } 49 | }, 50 | { 51 | "model": "inventory.inventory_attribute_values", 52 | "id": "7", 53 | "fields": { 54 | "attributevalue_id": "1", 55 | "inventory_id": "7" 56 | } 57 | }, 58 | { 59 | "model": "inventory.inventory_attribute_values", 60 | "id": "8", 61 | "fields": { 62 | "attributevalue_id": "1", 63 | "inventory_id": "8" 64 | } 65 | }, 66 | { 67 | "model": "inventory.inventory_attribute_values", 68 | "id": "9", 69 | "fields": { 70 | "attributevalue_id": "1", 71 | "inventory_id": "9" 72 | } 73 | }, 74 | { 75 | "model": "inventory.inventory_attribute_values", 76 | "id": "10", 77 | "fields": { 78 | "attributevalue_id": "1", 79 | "inventory_id": "10" 80 | } 81 | }, 82 | { 83 | "model": "inventory.inventory_attribute_values", 84 | "id": "11", 85 | "fields": { 86 | "attributevalue_id": "1", 87 | "inventory_id": "11" 88 | } 89 | }, 90 | { 91 | "model": "inventory.inventory_attribute_values", 92 | "id": "12", 93 | "fields": { 94 | "attributevalue_id": "1", 95 | "inventory_id": "12" 96 | } 97 | }, 98 | { 99 | "model": "inventory.inventory_attribute_values", 100 | "id": "13", 101 | "fields": { 102 | "attributevalue_id": "1", 103 | "inventory_id": "13" 104 | } 105 | }, 106 | { 107 | "model": "inventory.inventory_attribute_values", 108 | "id": "14", 109 | "fields": { 110 | "attributevalue_id": "1", 111 | "inventory_id": "14" 112 | } 113 | }, 114 | { 115 | "model": "inventory.inventory_attribute_values", 116 | "id": "15", 117 | "fields": { 118 | "attributevalue_id": "1", 119 | "inventory_id": "15" 120 | } 121 | }, 122 | { 123 | "model": "inventory.inventory_attribute_values", 124 | "id": "16", 125 | "fields": { 126 | "attributevalue_id": "1", 127 | "inventory_id": "16" 128 | } 129 | }, 130 | { 131 | "model": "inventory.inventory_attribute_values", 132 | "id": "17", 133 | "fields": { 134 | "attributevalue_id": "1", 135 | "inventory_id": "17" 136 | } 137 | }, 138 | { 139 | "model": "inventory.inventory_attribute_values", 140 | "id": "18", 141 | "fields": { 142 | "attributevalue_id": "1", 143 | "inventory_id": "18" 144 | } 145 | }, 146 | { 147 | "model": "inventory.inventory_attribute_values", 148 | "id": "19", 149 | "fields": { 150 | "attributevalue_id": "1", 151 | "inventory_id": "19" 152 | } 153 | }, 154 | { 155 | "model": "inventory.inventory_attribute_values", 156 | "id": "20", 157 | "fields": { 158 | "attributevalue_id": "1", 159 | "inventory_id": "20" 160 | } 161 | }, 162 | { 163 | "model": "inventory.inventory_attribute_values", 164 | "id": "21", 165 | "fields": { 166 | "attributevalue_id": "1", 167 | "inventory_id": "21" 168 | } 169 | }, 170 | { 171 | "model": "inventory.inventory_attribute_values", 172 | "id": "22", 173 | "fields": { 174 | "attributevalue_id": "1", 175 | "inventory_id": "22" 176 | } 177 | }, 178 | { 179 | "model": "inventory.inventory_attribute_values", 180 | "id": "23", 181 | "fields": { 182 | "attributevalue_id": "1", 183 | "inventory_id": "23" 184 | } 185 | }, 186 | { 187 | "model": "inventory.inventory_attribute_values", 188 | "id": "24", 189 | "fields": { 190 | "attributevalue_id": "1", 191 | "inventory_id": "24" 192 | } 193 | }, 194 | { 195 | "model": "inventory.inventory_attribute_values", 196 | "id": "25", 197 | "fields": { 198 | "attributevalue_id": "1", 199 | "inventory_id": "25" 200 | } 201 | }, 202 | { 203 | "model": "inventory.inventory_attribute_values", 204 | "id": "26", 205 | "fields": { 206 | "attributevalue_id": "1", 207 | "inventory_id": "26" 208 | } 209 | }, 210 | { 211 | "model": "inventory.inventory_attribute_values", 212 | "id": "27", 213 | "fields": { 214 | "attributevalue_id": "1", 215 | "inventory_id": "27" 216 | } 217 | }, 218 | { 219 | "model": "inventory.inventory_attribute_values", 220 | "id": "28", 221 | "fields": { 222 | "attributevalue_id": "1", 223 | "inventory_id": "28" 224 | } 225 | }, 226 | { 227 | "model": "inventory.inventory_attribute_values", 228 | "id": "29", 229 | "fields": { 230 | "attributevalue_id": "1", 231 | "inventory_id": "29" 232 | } 233 | }, 234 | { 235 | "model": "inventory.inventory_attribute_values", 236 | "id": "30", 237 | "fields": { 238 | "attributevalue_id": "1", 239 | "inventory_id": "30" 240 | } 241 | }, 242 | { 243 | "model": "inventory.inventory_attribute_values", 244 | "id": "31", 245 | "fields": { 246 | "attributevalue_id": "1", 247 | "inventory_id": "31" 248 | } 249 | }, 250 | { 251 | "model": "inventory.inventory_attribute_values", 252 | "id": "32", 253 | "fields": { 254 | "attributevalue_id": "1", 255 | "inventory_id": "32" 256 | } 257 | }, 258 | { 259 | "model": "inventory.inventory_attribute_values", 260 | "id": "33", 261 | "fields": { 262 | "attributevalue_id": "1", 263 | "inventory_id": "33" 264 | } 265 | }, 266 | { 267 | "model": "inventory.inventory_attribute_values", 268 | "id": "34", 269 | "fields": { 270 | "attributevalue_id": "1", 271 | "inventory_id": "34" 272 | } 273 | }, 274 | { 275 | "model": "inventory.inventory_attribute_values", 276 | "id": "35", 277 | "fields": { 278 | "attributevalue_id": "1", 279 | "inventory_id": "35" 280 | } 281 | }, 282 | { 283 | "model": "inventory.inventory_attribute_values", 284 | "id": "36", 285 | "fields": { 286 | "attributevalue_id": "1", 287 | "inventory_id": "36" 288 | } 289 | }, 290 | { 291 | "model": "inventory.inventory_attribute_values", 292 | "id": "37", 293 | "fields": { 294 | "attributevalue_id": "1", 295 | "inventory_id": "37" 296 | } 297 | }, 298 | { 299 | "model": "inventory.inventory_attribute_values", 300 | "id": "38", 301 | "fields": { 302 | "attributevalue_id": "1", 303 | "inventory_id": "38" 304 | } 305 | }, 306 | { 307 | "model": "inventory.inventory_attribute_values", 308 | "id": "39", 309 | "fields": { 310 | "attributevalue_id": "1", 311 | "inventory_id": "39" 312 | } 313 | }, 314 | { 315 | "model": "inventory.inventory_attribute_values", 316 | "id": "40", 317 | "fields": { 318 | "attributevalue_id": "1", 319 | "inventory_id": "40" 320 | } 321 | }, 322 | { 323 | "model": "inventory.inventory_attribute_values", 324 | "id": "41", 325 | "fields": { 326 | "attributevalue_id": "1", 327 | "inventory_id": "41" 328 | } 329 | }, 330 | { 331 | "model": "inventory.inventory_attribute_values", 332 | "id": "42", 333 | "fields": { 334 | "attributevalue_id": "1", 335 | "inventory_id": "42" 336 | } 337 | }, 338 | { 339 | "model": "inventory.inventory_attribute_values", 340 | "id": "43", 341 | "fields": { 342 | "attributevalue_id": "1", 343 | "inventory_id": "43" 344 | } 345 | }, 346 | { 347 | "model": "inventory.inventory_attribute_values", 348 | "id": "44", 349 | "fields": { 350 | "attributevalue_id": "1", 351 | "inventory_id": "44" 352 | } 353 | }, 354 | { 355 | "model": "inventory.inventory_attribute_values", 356 | "id": "45", 357 | "fields": { 358 | "attributevalue_id": "1", 359 | "inventory_id": "45" 360 | } 361 | }, 362 | { 363 | "model": "inventory.inventory_attribute_values", 364 | "id": "46", 365 | "fields": { 366 | "attributevalue_id": "1", 367 | "inventory_id": "46" 368 | } 369 | }, 370 | { 371 | "model": "inventory.inventory_attribute_values", 372 | "id": "47", 373 | "fields": { 374 | "attributevalue_id": "1", 375 | "inventory_id": "47" 376 | } 377 | }, 378 | { 379 | "model": "inventory.inventory_attribute_values", 380 | "id": "48", 381 | "fields": { 382 | "attributevalue_id": "1", 383 | "inventory_id": "48" 384 | } 385 | }, 386 | { 387 | "model": "inventory.inventory_attribute_values", 388 | "id": "49", 389 | "fields": { 390 | "attributevalue_id": "1", 391 | "inventory_id": "49" 392 | } 393 | } 394 | ] 395 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/fixtures/db_category_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "inventory.category", 4 | "pk": 1, 5 | "fields": { 6 | "name": "fashion", 7 | "slug": "fashion", 8 | "is_active": true 9 | } 10 | }, 11 | { 12 | "model": "inventory.category", 13 | "pk": 2, 14 | "fields": { 15 | "name": "woman", 16 | "slug": "woman", 17 | "is_active": true 18 | } 19 | }, 20 | { 21 | "model": "inventory.category", 22 | "pk": 3, 23 | "fields": { 24 | "name": "shoes", 25 | "slug": "shoes", 26 | "is_active": true 27 | } 28 | }, 29 | { 30 | "model": "inventory.category", 31 | "pk": 4, 32 | "fields": { 33 | "name": "sport and fitness", 34 | "slug": "sport-and-fitness", 35 | "is_active": true 36 | } 37 | }, 38 | { 39 | "model": "inventory.category", 40 | "pk": 5, 41 | "fields": { 42 | "name": "general purpose", 43 | "slug": "general-purpose", 44 | "is_active": true 45 | } 46 | }, 47 | { 48 | "model": "inventory.category", 49 | "pk": 6, 50 | "fields": { 51 | "name": "flats", 52 | "slug": "flats", 53 | "is_active": true 54 | } 55 | }, 56 | { 57 | "model": "inventory.category", 58 | "pk": 7, 59 | "fields": { 60 | "name": "casual", 61 | "slug": "casual", 62 | "is_active": true 63 | } 64 | }, 65 | { 66 | "model": "inventory.category", 67 | "pk": 8, 68 | "fields": { 69 | "name": "boots", 70 | "slug": "boots", 71 | "is_active": true 72 | } 73 | }, 74 | { 75 | "model": "inventory.category", 76 | "pk": 9, 77 | "fields": { 78 | "name": "heels", 79 | "slug": "heels", 80 | "is_active": true 81 | } 82 | }, 83 | { 84 | "model": "inventory.category", 85 | "pk": 10, 86 | "fields": { 87 | "name": "wedges", 88 | "slug": "wedges", 89 | "is_active": true 90 | } 91 | }, 92 | { 93 | "model": "inventory.category", 94 | "pk": 11, 95 | "fields": { 96 | "name": "booties", 97 | "slug": "booties", 98 | "is_active": true 99 | } 100 | }, 101 | { 102 | "model": "inventory.category", 103 | "pk": 12, 104 | "fields": { 105 | "name": "loafers", 106 | "slug": "loafers", 107 | "is_active": true 108 | } 109 | }, 110 | { 111 | "model": "inventory.category", 112 | "pk": 13, 113 | "fields": { 114 | "name": "sandalls", 115 | "slug": "sandalls", 116 | "is_active": true 117 | } 118 | }, 119 | { 120 | "model": "inventory.category", 121 | "pk": 14, 122 | "fields": { 123 | "name": "slip-ons", 124 | "slug": "slip-ons", 125 | "is_active": true 126 | } 127 | }, 128 | { 129 | "model": "inventory.category", 130 | "pk": 15, 131 | "fields": { 132 | "name": "oxfords", 133 | "slug": "oxfords", 134 | "is_active": true 135 | } 136 | }, 137 | { 138 | "model": "inventory.category", 139 | "pk": 16, 140 | "fields": { 141 | "name": "slippers", 142 | "slug": "slippers", 143 | "is_active": true 144 | } 145 | }, 146 | { 147 | "model": "inventory.category", 148 | "pk": 17, 149 | "fields": { 150 | "name": "golf", 151 | "slug": "golf", 152 | "is_active": true 153 | } 154 | }, 155 | { 156 | "model": "inventory.category", 157 | "pk": 18, 158 | "fields": { 159 | "name": "trainers", 160 | "slug": "trainers", 161 | "is_active": true 162 | } 163 | }, 164 | { 165 | "model": "inventory.category", 166 | "pk": 19, 167 | "fields": { 168 | "name": "running", 169 | "slug": "running", 170 | "is_active": true 171 | } 172 | }, 173 | { 174 | "model": "inventory.category", 175 | "pk": 20, 176 | "fields": { 177 | "name": "pumps", 178 | "slug": "pumps", 179 | "is_active": true 180 | } 181 | }, 182 | { 183 | "model": "inventory.category", 184 | "pk": 21, 185 | "fields": { 186 | "name": "patio", 187 | "slug": "patio", 188 | "is_active": true 189 | } 190 | }, 191 | { 192 | "model": "inventory.category", 193 | "pk": 22, 194 | "fields": { 195 | "name": "designer", 196 | "slug": "designer", 197 | "is_active": true 198 | } 199 | }, 200 | { 201 | "model": "inventory.category", 202 | "pk": 23, 203 | "fields": { 204 | "name": "contemporary", 205 | "slug": "contemporary", 206 | "is_active": true 207 | } 208 | }, 209 | { 210 | "model": "inventory.category", 211 | "pk": 24, 212 | "fields": { 213 | "name": "comfort", 214 | "slug": "comfort", 215 | "is_active": true 216 | } 217 | }, 218 | { 219 | "model": "inventory.category", 220 | "pk": 25, 221 | "fields": { 222 | "name": "cross-training", 223 | "slug": "cross-training", 224 | "is_active": true 225 | } 226 | }, 227 | { 228 | "model": "inventory.category", 229 | "pk": 26, 230 | "fields": { 231 | "name": "formal", 232 | "slug": "formal", 233 | "is_active": true 234 | } 235 | }, 236 | { 237 | "model": "inventory.category", 238 | "pk": 27, 239 | "fields": { 240 | "name": "safety", 241 | "slug": "safety", 242 | "is_active": true 243 | } 244 | }, 245 | { 246 | "model": "inventory.category", 247 | "pk": 28, 248 | "fields": { 249 | "name": "hiking", 250 | "slug": "hiking", 251 | "is_active": true 252 | } 253 | }, 254 | { 255 | "model": "inventory.category", 256 | "pk": 29, 257 | "fields": { 258 | "name": "eco-friendly", 259 | "slug": "eco-friendly", 260 | "is_active": true 261 | } 262 | }, 263 | { 264 | "model": "inventory.category", 265 | "pk": 30, 266 | "fields": { 267 | "name": "cycling", 268 | "slug": "cycling", 269 | "is_active": true 270 | } 271 | }, 272 | { 273 | "model": "inventory.category", 274 | "pk": 31, 275 | "fields": { 276 | "name": "moccasins", 277 | "slug": "moccasins", 278 | "is_active": true 279 | } 280 | }, 281 | { 282 | "model": "inventory.category", 283 | "pk": 32, 284 | "fields": { 285 | "name": "kids", 286 | "slug": "kids", 287 | "is_active": true 288 | } 289 | }, 290 | { 291 | "model": "inventory.category", 292 | "pk": 33, 293 | "fields": { 294 | "name": "halloween", 295 | "slug": "halloween", 296 | "is_active": true 297 | } 298 | }, 299 | { 300 | "model": "inventory.category", 301 | "pk": 34, 302 | "fields": { 303 | "name": "winter", 304 | "slug": "winter", 305 | "is_active": true 306 | } 307 | }, 308 | { 309 | "model": "inventory.category", 310 | "pk": 35, 311 | "fields": { 312 | "name": "baseball", 313 | "slug": "baseball", 314 | "is_active": true 315 | } 316 | } 317 | ] 318 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/fixtures/db_product_category_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "inventory.product_category", 4 | "id": "1", 5 | "fields": { 6 | "product_id": "1", 7 | "category_id": "1" 8 | } 9 | }, 10 | { 11 | "model": "inventory.product_category", 12 | "id": "2", 13 | "fields": { 14 | "product_id": "2", 15 | "category_id": "2" 16 | } 17 | }, 18 | { 19 | "model": "inventory.product_category", 20 | "id": "3", 21 | "fields": { 22 | "product_id": "3", 23 | "category_id": "3" 24 | } 25 | }, 26 | { 27 | "model": "inventory.product_category", 28 | "id": "4", 29 | "fields": { 30 | "product_id": "4", 31 | "category_id": "4" 32 | } 33 | }, 34 | { 35 | "model": "inventory.product_category", 36 | "id": "5", 37 | "fields": { 38 | "product_id": "5", 39 | "category_id": "5" 40 | } 41 | }, 42 | { 43 | "model": "inventory.product_category", 44 | "id": "6", 45 | "fields": { 46 | "product_id": "6", 47 | "category_id": "6" 48 | } 49 | }, 50 | { 51 | "model": "inventory.product_category", 52 | "id": "7", 53 | "fields": { 54 | "product_id": "7", 55 | "category_id": "7" 56 | } 57 | }, 58 | { 59 | "model": "inventory.product_category", 60 | "id": "8", 61 | "fields": { 62 | "product_id": "8", 63 | "category_id": "8" 64 | } 65 | }, 66 | 67 | { 68 | "model": "inventory.product_category", 69 | "id": "9", 70 | "fields": { 71 | "product_id": "9", 72 | "category_id": "1" 73 | } 74 | }, 75 | { 76 | "model": "inventory.product_category", 77 | "id": "10", 78 | "fields": { 79 | "product_id": "10", 80 | "category_id": "2" 81 | } 82 | }, 83 | { 84 | "model": "inventory.product_category", 85 | "id": "11", 86 | "fields": { 87 | "product_id": "11", 88 | "category_id": "3" 89 | } 90 | }, 91 | { 92 | "model": "inventory.product_category", 93 | "id": "12", 94 | "fields": { 95 | "product_id": "12", 96 | "category_id": "4" 97 | } 98 | }, 99 | 100 | { 101 | "model": "inventory.product_category", 102 | "id": "13", 103 | "fields": { 104 | "product_id": "13", 105 | "category_id": "5" 106 | } 107 | }, 108 | { 109 | "model": "inventory.product_category", 110 | "id": "14", 111 | "fields": { 112 | "product_id": "14", 113 | "category_id": "6" 114 | } 115 | }, 116 | { 117 | "model": "inventory.product_category", 118 | "id": "15", 119 | "fields": { 120 | "product_id": "15", 121 | "category_id": "7" 122 | } 123 | }, 124 | { 125 | "model": "inventory.product_category", 126 | "id": "16", 127 | "fields": { 128 | "product_id": "16", 129 | "category_id": "8" 130 | } 131 | }, 132 | 133 | { 134 | "model": "inventory.product_category", 135 | "id": "17", 136 | "fields": { 137 | "product_id": "1", 138 | "category_id": "9" 139 | } 140 | }, 141 | { 142 | "model": "inventory.product_category", 143 | "id": "17", 144 | "fields": { 145 | "product_id": "2", 146 | "category_id": "1" 147 | } 148 | }, 149 | { 150 | "model": "inventory.product_category", 151 | "id": "18", 152 | "fields": { 153 | "product_id": "18", 154 | "category_id": "2" 155 | } 156 | }, 157 | { 158 | "model": "inventory.product_category", 159 | "id": "19", 160 | "fields": { 161 | "product_id": "19", 162 | "category_id": "3" 163 | } 164 | }, 165 | { 166 | "model": "inventory.product_category", 167 | "id": "20", 168 | "fields": { 169 | "product_id": "20", 170 | "category_id": "4" 171 | } 172 | }, 173 | { 174 | "model": "inventory.product_category", 175 | "id": "21", 176 | "fields": { 177 | "product_id": "21", 178 | "category_id": "5" 179 | } 180 | }, 181 | { 182 | "model": "inventory.product_category", 183 | "id": "22", 184 | "fields": { 185 | "product_id": "22", 186 | "category_id": "6" 187 | } 188 | }, 189 | { 190 | "model": "inventory.product_category", 191 | "id": "23", 192 | "fields": { 193 | "product_id": "23", 194 | "category_id": "7" 195 | } 196 | }, 197 | { 198 | "model": "inventory.product_category", 199 | "id": "24", 200 | "fields": { 201 | "product_id": "24", 202 | "category_id": "8" 203 | } 204 | }, 205 | { 206 | "model": "inventory.product_category", 207 | "id": "25", 208 | "fields": { 209 | "product_id": "25", 210 | "category_id": "9" 211 | } 212 | }, 213 | { 214 | "model": "inventory.product_category", 215 | "id": "26", 216 | "fields": { 217 | "product_id": "26", 218 | "category_id": "3" 219 | } 220 | }, 221 | { 222 | "model": "inventory.product_category", 223 | "id": "27", 224 | "fields": { 225 | "product_id": "27", 226 | "category_id": "4" 227 | } 228 | }, 229 | { 230 | "model": "inventory.product_category", 231 | "id": "28", 232 | "fields": { 233 | "product_id": "28", 234 | "category_id": "1" 235 | } 236 | }, 237 | { 238 | "model": "inventory.product_category", 239 | "id": "29", 240 | "fields": { 241 | "product_id": "29", 242 | "category_id": "2" 243 | } 244 | }, 245 | { 246 | "model": "inventory.product_category", 247 | "id": "30", 248 | "fields": { 249 | "product_id": "30", 250 | "category_id": "3" 251 | } 252 | }, 253 | { 254 | "model": "inventory.product_category", 255 | "id": "31", 256 | "fields": { 257 | "product_id": "31", 258 | "category_id": "4" 259 | } 260 | }, 261 | { 262 | "model": "inventory.product_category", 263 | "id": "32", 264 | "fields": { 265 | "product_id": "32", 266 | "category_id": "1" 267 | } 268 | }, 269 | { 270 | "model": "inventory.product_category", 271 | "id": "33", 272 | "fields": { 273 | "product_id": "33", 274 | "category_id": "2" 275 | } 276 | }, 277 | { 278 | "model": "inventory.product_category", 279 | "id": "34", 280 | "fields": { 281 | "product_id": "34", 282 | "category_id": "3" 283 | } 284 | }, 285 | { 286 | "model": "inventory.product_category", 287 | "id": "35", 288 | "fields": { 289 | "product_id": "35", 290 | "category_id": "4" 291 | } 292 | }, 293 | { 294 | "model": "inventory.product_category", 295 | "id": "36", 296 | "fields": { 297 | "product_id": "36", 298 | "category_id": "1" 299 | } 300 | }, 301 | { 302 | "model": "inventory.product_category", 303 | "id": "37", 304 | "fields": { 305 | "product_id": "37", 306 | "category_id": "2" 307 | } 308 | }, 309 | { 310 | "model": "inventory.product_category", 311 | "id": "38", 312 | "fields": { 313 | "product_id": "38", 314 | "category_id": "3" 315 | } 316 | }, 317 | { 318 | "model": "inventory.product_category", 319 | "id": "39", 320 | "fields": { 321 | "product_id": "39", 322 | "category_id": "4" 323 | } 324 | }, 325 | { 326 | "model": "inventory.product_category", 327 | "id": "40", 328 | "fields": { 329 | "product_id": "40", 330 | "category_id": "1" 331 | } 332 | }, 333 | { 334 | "model": "inventory.product_category", 335 | "id": "41", 336 | "fields": { 337 | "product_id": "41", 338 | "category_id": "2" 339 | } 340 | }, 341 | { 342 | "model": "inventory.product_category", 343 | "id": "42", 344 | "fields": { 345 | "product_id": "42", 346 | "category_id": "3" 347 | } 348 | }, 349 | { 350 | "model": "inventory.product_category", 351 | "id": "43", 352 | "fields": { 353 | "product_id": "43", 354 | "category_id": "4" 355 | } 356 | }, 357 | { 358 | "model": "inventory.product_category", 359 | "id": "44", 360 | "fields": { 361 | "product_id": "44", 362 | "category_id": "1" 363 | } 364 | }, 365 | { 366 | "model": "inventory.product_category", 367 | "id": "45", 368 | "fields": { 369 | "product_id": "45", 370 | "category_id": "2" 371 | } 372 | }, 373 | { 374 | "model": "inventory.product_category", 375 | "id": "46", 376 | "fields": { 377 | "product_id": "46", 378 | "category_id": "3" 379 | } 380 | }, 381 | { 382 | "model": "inventory.product_category", 383 | "id": "47", 384 | "fields": { 385 | "product_id": "47", 386 | "category_id": "4" 387 | } 388 | }, 389 | { 390 | "model": "inventory.product_category", 391 | "id": "48", 392 | "fields": { 393 | "product_id": "48", 394 | "category_id": "1" 395 | } 396 | }, 397 | { 398 | "model": "inventory.product_category", 399 | "id": "49", 400 | "fields": { 401 | "product_id": "49", 402 | "category_id": "2" 403 | } 404 | }, 405 | { 406 | "model": "inventory.product_category", 407 | "id": "50", 408 | "fields": { 409 | "product_id": "50", 410 | "category_id": "2" 411 | } 412 | } 413 | ] 414 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/fixtures/db_stock_control_fixture_50.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "inventory.stockcontrol", 4 | "id": "1", 5 | "fields": { 6 | "inventory": "1", 7 | "last_checked": "2021-09-01T13:20:30+03:00", 8 | "units": "135" 9 | } 10 | }, 11 | { 12 | "model": "inventory.stockcontrol", 13 | "id": "2", 14 | "fields": { 15 | "inventory": "2", 16 | "last_checked": "2021-09-01T13:20:30+03:00", 17 | "units": "188" 18 | } 19 | }, 20 | { 21 | "model": "inventory.stockcontrol", 22 | "id": "3", 23 | "fields": { 24 | "inventory": "3", 25 | "last_checked": "2021-09-01T13:20:30+03:00", 26 | "units": "2" 27 | } 28 | }, 29 | { 30 | "model": "inventory.stockcontrol", 31 | "id": "4", 32 | "fields": { 33 | "inventory": "4", 34 | "last_checked": "2021-09-01T13:20:30+03:00", 35 | "units": "153" 36 | } 37 | }, 38 | { 39 | "model": "inventory.stockcontrol", 40 | "id": "5", 41 | "fields": { 42 | "inventory": "5", 43 | "last_checked": "2021-09-01T13:20:30+03:00", 44 | "units": "84" 45 | } 46 | }, 47 | { 48 | "model": "inventory.stockcontrol", 49 | "id": "6", 50 | "fields": { 51 | "inventory": "6", 52 | "last_checked": "2021-09-01T13:20:30+03:00", 53 | "units": "92" 54 | } 55 | }, 56 | { 57 | "model": "inventory.stockcontrol", 58 | "id": "7", 59 | "fields": { 60 | "inventory": "7", 61 | "last_checked": "2021-09-01T13:20:30+03:00", 62 | "units": "153" 63 | } 64 | }, 65 | { 66 | "model": "inventory.stockcontrol", 67 | "id": "8", 68 | "fields": { 69 | "inventory": "8", 70 | "last_checked": "2021-09-01T13:20:30+03:00", 71 | "units": "153" 72 | } 73 | }, 74 | { 75 | "model": "inventory.stockcontrol", 76 | "id": "9", 77 | "fields": { 78 | "inventory": "9", 79 | "last_checked": "2021-09-01T13:20:30+03:00", 80 | "units": "113" 81 | } 82 | }, 83 | { 84 | "model": "inventory.stockcontrol", 85 | "id": "10", 86 | "fields": { 87 | "inventory": "10", 88 | "last_checked": "2021-09-01T13:20:30+03:00", 89 | "units": "77" 90 | } 91 | }, 92 | { 93 | "model": "inventory.stockcontrol", 94 | "id": "11", 95 | "fields": { 96 | "inventory": "11", 97 | "last_checked": "2021-09-01T13:20:30+03:00", 98 | "units": "181" 99 | } 100 | }, 101 | { 102 | "model": "inventory.stockcontrol", 103 | "id": "12", 104 | "fields": { 105 | "inventory": "12", 106 | "last_checked": "2021-09-01T13:20:30+03:00", 107 | "units": "178" 108 | } 109 | }, 110 | { 111 | "model": "inventory.stockcontrol", 112 | "id": "13", 113 | "fields": { 114 | "inventory": "13", 115 | "last_checked": "2021-09-01T13:20:30+03:00", 116 | "units": "43" 117 | } 118 | }, 119 | { 120 | "model": "inventory.stockcontrol", 121 | "id": "14", 122 | "fields": { 123 | "inventory": "14", 124 | "last_checked": "2021-09-01T13:20:30+03:00", 125 | "units": "18" 126 | } 127 | }, 128 | { 129 | "model": "inventory.stockcontrol", 130 | "id": "15", 131 | "fields": { 132 | "inventory": "15", 133 | "last_checked": "2021-09-01T13:20:30+03:00", 134 | "units": "53" 135 | } 136 | }, 137 | { 138 | "model": "inventory.stockcontrol", 139 | "id": "16", 140 | "fields": { 141 | "inventory": "16", 142 | "last_checked": "2021-09-01T13:20:30+03:00", 143 | "units": "83" 144 | } 145 | }, 146 | { 147 | "model": "inventory.stockcontrol", 148 | "id": "17", 149 | "fields": { 150 | "inventory": "17", 151 | "last_checked": "2021-09-01T13:20:30+03:00", 152 | "units": "102" 153 | } 154 | }, 155 | { 156 | "model": "inventory.stockcontrol", 157 | "id": "18", 158 | "fields": { 159 | "inventory": "18", 160 | "last_checked": "2021-09-01T13:20:30+03:00", 161 | "units": "133" 162 | } 163 | }, 164 | { 165 | "model": "inventory.stockcontrol", 166 | "id": "19", 167 | "fields": { 168 | "inventory": "19", 169 | "last_checked": "2021-09-01T13:20:30+03:00", 170 | "units": "20" 171 | } 172 | }, 173 | { 174 | "model": "inventory.stockcontrol", 175 | "id": "20", 176 | "fields": { 177 | "inventory": "20", 178 | "last_checked": "2021-09-01T13:20:30+03:00", 179 | "units": "172" 180 | } 181 | }, 182 | { 183 | "model": "inventory.stockcontrol", 184 | "id": "21", 185 | "fields": { 186 | "inventory": "21", 187 | "last_checked": "2021-09-01T13:20:30+03:00", 188 | "units": "116" 189 | } 190 | }, 191 | { 192 | "model": "inventory.stockcontrol", 193 | "id": "22", 194 | "fields": { 195 | "inventory": "22", 196 | "last_checked": "2021-09-01T13:20:30+03:00", 197 | "units": "3" 198 | } 199 | }, 200 | { 201 | "model": "inventory.stockcontrol", 202 | "id": "23", 203 | "fields": { 204 | "inventory": "23", 205 | "last_checked": "2021-09-01T13:20:30+03:00", 206 | "units": "5" 207 | } 208 | }, 209 | { 210 | "model": "inventory.stockcontrol", 211 | "id": "24", 212 | "fields": { 213 | "inventory": "24", 214 | "last_checked": "2021-09-01T13:20:30+03:00", 215 | "units": "5" 216 | } 217 | }, 218 | { 219 | "model": "inventory.stockcontrol", 220 | "id": "25", 221 | "fields": { 222 | "inventory": "25", 223 | "last_checked": "2021-09-01T13:20:30+03:00", 224 | "units": "140" 225 | } 226 | }, 227 | { 228 | "model": "inventory.stockcontrol", 229 | "id": "26", 230 | "fields": { 231 | "inventory": "26", 232 | "last_checked": "2021-09-01T13:20:30+03:00", 233 | "units": "63" 234 | } 235 | }, 236 | { 237 | "model": "inventory.stockcontrol", 238 | "id": "27", 239 | "fields": { 240 | "inventory": "27", 241 | "last_checked": "2021-09-01T13:20:30+03:00", 242 | "units": "51" 243 | } 244 | }, 245 | { 246 | "model": "inventory.stockcontrol", 247 | "id": "28", 248 | "fields": { 249 | "inventory": "28", 250 | "last_checked": "2021-09-01T13:20:30+03:00", 251 | "units": "46" 252 | } 253 | }, 254 | { 255 | "model": "inventory.stockcontrol", 256 | "id": "29", 257 | "fields": { 258 | "inventory": "29", 259 | "last_checked": "2021-09-01T13:20:30+03:00", 260 | "units": "158" 261 | } 262 | }, 263 | { 264 | "model": "inventory.stockcontrol", 265 | "id": "30", 266 | "fields": { 267 | "inventory": "30", 268 | "last_checked": "2021-09-01T13:20:30+03:00", 269 | "units": "95" 270 | } 271 | }, 272 | { 273 | "model": "inventory.stockcontrol", 274 | "id": "31", 275 | "fields": { 276 | "inventory": "31", 277 | "last_checked": "2021-09-01T13:20:30+03:00", 278 | "units": "134" 279 | } 280 | }, 281 | { 282 | "model": "inventory.stockcontrol", 283 | "id": "32", 284 | "fields": { 285 | "inventory": "32", 286 | "last_checked": "2021-09-01T13:20:30+03:00", 287 | "units": "110" 288 | } 289 | }, 290 | { 291 | "model": "inventory.stockcontrol", 292 | "id": "33", 293 | "fields": { 294 | "inventory": "33", 295 | "last_checked": "2021-09-01T13:20:30+03:00", 296 | "units": "21" 297 | } 298 | }, 299 | { 300 | "model": "inventory.stockcontrol", 301 | "id": "34", 302 | "fields": { 303 | "inventory": "34", 304 | "last_checked": "2021-09-01T13:20:30+03:00", 305 | "units": "164" 306 | } 307 | }, 308 | { 309 | "model": "inventory.stockcontrol", 310 | "id": "35", 311 | "fields": { 312 | "inventory": "35", 313 | "last_checked": "2021-09-01T13:20:30+03:00", 314 | "units": "1" 315 | } 316 | }, 317 | { 318 | "model": "inventory.stockcontrol", 319 | "id": "36", 320 | "fields": { 321 | "inventory": "36", 322 | "last_checked": "2021-09-01T13:20:30+03:00", 323 | "units": "37" 324 | } 325 | }, 326 | { 327 | "model": "inventory.stockcontrol", 328 | "id": "37", 329 | "fields": { 330 | "inventory": "37", 331 | "last_checked": "2021-09-01T13:20:30+03:00", 332 | "units": "137" 333 | } 334 | }, 335 | { 336 | "model": "inventory.stockcontrol", 337 | "id": "38", 338 | "fields": { 339 | "inventory": "38", 340 | "last_checked": "2021-09-01T13:20:30+03:00", 341 | "units": "88" 342 | } 343 | }, 344 | { 345 | "model": "inventory.stockcontrol", 346 | "id": "39", 347 | "fields": { 348 | "inventory": "39", 349 | "last_checked": "2021-09-01T13:20:30+03:00", 350 | "units": "145" 351 | } 352 | }, 353 | { 354 | "model": "inventory.stockcontrol", 355 | "id": "40", 356 | "fields": { 357 | "inventory": "40", 358 | "last_checked": "2021-09-01T13:20:30+03:00", 359 | "units": "181" 360 | } 361 | }, 362 | { 363 | "model": "inventory.stockcontrol", 364 | "id": "41", 365 | "fields": { 366 | "inventory": "41", 367 | "last_checked": "2021-09-01T13:20:30+03:00", 368 | "units": "113" 369 | } 370 | }, 371 | { 372 | "model": "inventory.stockcontrol", 373 | "id": "42", 374 | "fields": { 375 | "inventory": "42", 376 | "last_checked": "2021-09-01T13:20:30+03:00", 377 | "units": "102" 378 | } 379 | }, 380 | { 381 | "model": "inventory.stockcontrol", 382 | "id": "43", 383 | "fields": { 384 | "inventory": "43", 385 | "last_checked": "2021-09-01T13:20:30+03:00", 386 | "units": "161" 387 | } 388 | }, 389 | { 390 | "model": "inventory.stockcontrol", 391 | "id": "44", 392 | "fields": { 393 | "inventory": "44", 394 | "last_checked": "2021-09-01T13:20:30+03:00", 395 | "units": "71" 396 | } 397 | }, 398 | { 399 | "model": "inventory.stockcontrol", 400 | "id": "45", 401 | "fields": { 402 | "inventory": "45", 403 | "last_checked": "2021-09-01T13:20:30+03:00", 404 | "units": "180" 405 | } 406 | }, 407 | { 408 | "model": "inventory.stockcontrol", 409 | "id": "46", 410 | "fields": { 411 | "inventory": "46", 412 | "last_checked": "2021-09-01T13:20:30+03:00", 413 | "units": "128" 414 | } 415 | }, 416 | { 417 | "model": "inventory.stockcontrol", 418 | "id": "47", 419 | "fields": { 420 | "inventory": "47", 421 | "last_checked": "2021-09-01T13:20:30+03:00", 422 | "units": "12" 423 | } 424 | }, 425 | { 426 | "model": "inventory.stockcontrol", 427 | "id": "48", 428 | "fields": { 429 | "inventory": "48", 430 | "last_checked": "2021-09-01T13:20:30+03:00", 431 | "units": "66" 432 | } 433 | }, 434 | { 435 | "model": "inventory.stockcontrol", 436 | "id": "49", 437 | "fields": { 438 | "inventory": "49", 439 | "last_checked": "2021-09-01T13:20:30+03:00", 440 | "units": "115" 441 | } 442 | } 443 | ] 444 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/management/commands/__pycache__/load-fixtures.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/inventory/management/commands/__pycache__/load-fixtures.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/management/commands/load-fixtures.py: -------------------------------------------------------------------------------- 1 | from django.core.management import call_command 2 | from django.core.management.base import BaseCommand 3 | 4 | class Command(BaseCommand): 5 | def handle(self, *args, **kwargs): 6 | call_command("makemigrations") 7 | call_command("migrate") 8 | call_command("loaddata", "db_admin_fixture_50.json") 9 | call_command("loaddata", "db_category_fixture_50.json") 10 | call_command("loaddata", "db_product_fixture_50.json") 11 | call_command("loaddata", "db_product_category_fixture_50.json") 12 | call_command("loaddata", "db_attribute_fixture_50.json") 13 | call_command("loaddata", "db_attribute_value_fixture_50.json") 14 | call_command("loaddata", "db_inventory_fixture_50.json") 15 | call_command("loaddata", "db_attribute_values_fixture_50.json") 16 | call_command("loaddata", "db_image_fixture_50.json") 17 | call_command("loaddata", "db_stock_control_fixture_50.json") -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.6 on 2022-07-07 12:13 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | initial = True 10 | 11 | dependencies = [ 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Attribute', 17 | fields=[ 18 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 19 | ('name', models.CharField(max_length=50)), 20 | ('description', models.TextField()), 21 | ], 22 | ), 23 | migrations.CreateModel( 24 | name='AttributeValue', 25 | fields=[ 26 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 27 | ('value', models.CharField(max_length=50)), 28 | ('attribute', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='attribute', to='inventory.attribute')), 29 | ], 30 | ), 31 | migrations.CreateModel( 32 | name='Category', 33 | fields=[ 34 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 35 | ('name', models.CharField(max_length=50)), 36 | ('slug', models.SlugField()), 37 | ('is_active', models.BooleanField()), 38 | ], 39 | options={ 40 | 'verbose_name_plural': 'Categories', 41 | }, 42 | ), 43 | migrations.CreateModel( 44 | name='Inventory', 45 | fields=[ 46 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 47 | ('is_active', models.BooleanField()), 48 | ('is_default', models.BooleanField()), 49 | ('price', models.DecimalField(decimal_places=2, max_digits=5)), 50 | ('created_at', models.DateTimeField(auto_now_add=True)), 51 | ('sku', models.CharField(max_length=20, unique=True)), 52 | ('attribute_values', models.ManyToManyField(to='inventory.attributevalue')), 53 | ], 54 | options={ 55 | 'verbose_name_plural': 'Inventory', 56 | }, 57 | ), 58 | migrations.CreateModel( 59 | name='StockControl', 60 | fields=[ 61 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 62 | ('last_checked', models.DateTimeField(editable=False)), 63 | ('units', models.IntegerField(default=0)), 64 | ('inventory', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='inventory.inventory')), 65 | ], 66 | options={ 67 | 'verbose_name_plural': 'Stock Control', 68 | }, 69 | ), 70 | migrations.CreateModel( 71 | name='Product', 72 | fields=[ 73 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 74 | ('name', models.CharField(max_length=50)), 75 | ('description', models.TextField()), 76 | ('slug', models.SlugField()), 77 | ('is_active', models.BooleanField()), 78 | ('category', models.ManyToManyField(to='inventory.category')), 79 | ], 80 | ), 81 | migrations.AddField( 82 | model_name='inventory', 83 | name='product', 84 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='product', to='inventory.product'), 85 | ), 86 | migrations.CreateModel( 87 | name='Image', 88 | fields=[ 89 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 90 | ('url', models.ImageField(upload_to=None)), 91 | ('alternative_text', models.CharField(max_length=50)), 92 | ('is_feature', models.BooleanField()), 93 | ('inventory', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='inventory.inventory')), 94 | ], 95 | ), 96 | ] 97 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/inventory/migrations/__init__.py -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/inventory/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/case-study-1/ecommerce/inventory/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | class Category(models.Model): 5 | name = models.CharField(max_length=50) 6 | slug = models.SlugField() 7 | is_active = models.BooleanField() 8 | 9 | class Meta: 10 | verbose_name_plural = "Categories" 11 | 12 | def __str__(self): 13 | return self.name 14 | 15 | 16 | class Product(models.Model): 17 | name = models.CharField(max_length=50) 18 | description = models.TextField() 19 | slug = models.SlugField() 20 | is_active = models.BooleanField() 21 | 22 | category = models.ManyToManyField(Category) 23 | 24 | def __str__(self): 25 | return self.name 26 | 27 | 28 | class Attribute(models.Model): 29 | name = models.CharField(max_length=50) 30 | description = models.TextField() 31 | 32 | def __str__(self): 33 | return self.name 34 | 35 | 36 | class AttributeValue(models.Model): 37 | value = models.CharField(max_length=50) 38 | 39 | attribute = models.ForeignKey( 40 | Attribute, related_name="attribute", on_delete=models.CASCADE 41 | ) 42 | 43 | def __str__(self): 44 | return self.value 45 | # return f"{self.attribute.name}:{self.value}" 46 | 47 | 48 | class Inventory(models.Model): 49 | is_active = models.BooleanField() 50 | is_default = models.BooleanField() 51 | price = models.DecimalField( 52 | max_digits=5, 53 | decimal_places=2, 54 | ) 55 | created_at = models.DateTimeField(auto_now_add=True, editable=False) 56 | sku = models.CharField( 57 | max_length=20, 58 | unique=True, 59 | ) 60 | # sku = models.UUIDField(default=uuid.uuid4, editable=False) 61 | 62 | product = models.ForeignKey( 63 | Product, related_name="product", on_delete=models.CASCADE 64 | ) 65 | attribute_values = models.ManyToManyField(AttributeValue) 66 | 67 | class Meta: 68 | verbose_name_plural = "Inventory" 69 | 70 | def __str__(self): 71 | return self.product.name 72 | 73 | 74 | class StockControl(models.Model): 75 | last_checked = models.DateTimeField(auto_now_add=False, editable=False) 76 | units = models.IntegerField(default=0) 77 | 78 | inventory = models.OneToOneField(Inventory, on_delete=models.CASCADE) 79 | 80 | class Meta: 81 | verbose_name_plural = "Stock Control" 82 | 83 | 84 | class Image(models.Model): 85 | url = models.ImageField(upload_to=None) 86 | alternative_text = models.CharField(max_length=50) 87 | is_feature = models.BooleanField() 88 | inventory = models.ForeignKey(Inventory, on_delete=models.CASCADE) 89 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/inventory/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for ecommerce project. 3 | 4 | Generated by 'django-admin startproject' using Django 4.0.6. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/4.0/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/4.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-(r+0e&@p5emt5+cy#sj_*t5svwlneme^(c9kk6cr*!qi&1opf+' 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 | 'ecommerce.inventory', 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 = 'ecommerce.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 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 = 'ecommerce.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': BASE_DIR / 'db.sqlite3', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_TZ = True 114 | 115 | 116 | # Static files (CSS, JavaScript, Images) 117 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ 118 | 119 | STATIC_URL = 'static/' 120 | 121 | # Default primary key field type 122 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 123 | 124 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 125 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/urls.py: -------------------------------------------------------------------------------- 1 | """ecommerce URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/4.0/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 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | ] 22 | -------------------------------------------------------------------------------- /case-study-1/ecommerce/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for ecommerce 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.0/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', 'ecommerce.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /case-study-1/manage.py: -------------------------------------------------------------------------------- 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', 'ecommerce.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() 23 | -------------------------------------------------------------------------------- /choice-field-option/Starting_codebase.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/choice-field-option/Starting_codebase.zip -------------------------------------------------------------------------------- /choice-field-option/final_code.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/choice-field-option/final_code.zip -------------------------------------------------------------------------------- /codebase-0/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/.DS_Store -------------------------------------------------------------------------------- /codebase-0/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/core/__init__.py -------------------------------------------------------------------------------- /codebase-0/core/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/core/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/core/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/core/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/core/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/core/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/core/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/core/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/core/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for core 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.0/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', 'core.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /codebase-0/core/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for core project. 3 | 4 | Generated by 'django-admin startproject' using Django 4.0.5. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/4.0/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/4.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-$)(!(09y7eh)^9_3ul72sda^=zq!eplt(#s78u7n@9m)w^r76%' 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 | 'inventory' 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 = 'core.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 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 = 'core.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': BASE_DIR / 'db.sqlite3', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_TZ = True 114 | 115 | 116 | # Static files (CSS, JavaScript, Images) 117 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ 118 | 119 | STATIC_URL = 'static/' 120 | 121 | # Default primary key field type 122 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 123 | 124 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 125 | -------------------------------------------------------------------------------- /codebase-0/core/urls.py: -------------------------------------------------------------------------------- 1 | """core URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/4.0/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 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | ] 22 | -------------------------------------------------------------------------------- /codebase-0/core/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for core 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.0/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', 'core.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /codebase-0/inventory/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/inventory/__init__.py -------------------------------------------------------------------------------- /codebase-0/inventory/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/inventory/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/inventory/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/inventory/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/inventory/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/inventory/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/inventory/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/inventory/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/inventory/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import Product, Brand, Category, Stock 3 | 4 | admin.site.register(Product) 5 | admin.site.register(Brand) 6 | admin.site.register(Category) 7 | admin.site.register(Stock) 8 | -------------------------------------------------------------------------------- /codebase-0/inventory/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class InventoryConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'inventory' 7 | -------------------------------------------------------------------------------- /codebase-0/inventory/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/inventory/migrations/__init__.py -------------------------------------------------------------------------------- /codebase-0/inventory/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/inventory/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/inventory/migrations/__pycache__/0002_alter_product_category_stock.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/inventory/migrations/__pycache__/0002_alter_product_category_stock.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/inventory/migrations/__pycache__/0002_alter_product_name.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/inventory/migrations/__pycache__/0002_alter_product_name.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/inventory/migrations/__pycache__/0002_rename_name_product_the_name.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/inventory/migrations/__pycache__/0002_rename_name_product_the_name.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/inventory/migrations/__pycache__/0003_brand_alter_product_name.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/inventory/migrations/__pycache__/0003_brand_alter_product_name.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/inventory/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-0/inventory/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /codebase-0/inventory/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | class Brand(models.Model): 4 | brand_id = models.BigAutoField(primary_key=True) 5 | name = models.CharField(max_length=50) 6 | 7 | class Category(models.Model): 8 | name = models.CharField(max_length=50) 9 | 10 | class Meta: 11 | verbose_name_plural = "Categories" 12 | 13 | class Product(models.Model): 14 | the_name = models.CharField("Product Name", max_length=100, default="no-name", help_text="This is the help text") 15 | age = models.IntegerField() 16 | is_active = models.BooleanField(default=True) 17 | # category = models.ForeignKey(Category, on_delete=models.CASCADE) 18 | category = models.ManyToManyField(Category) 19 | 20 | class Meta: 21 | ordering = ["age"] 22 | 23 | def __str__(self): 24 | return f"Product name: {self.name}" 25 | 26 | class Stock(models.Model): 27 | units = models.BigIntegerField() 28 | product = models.OneToOneField(Product, on_delete=models.CASCADE) -------------------------------------------------------------------------------- /codebase-0/inventory/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /codebase-0/inventory/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /codebase-0/manage.py: -------------------------------------------------------------------------------- 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', 'core.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() 23 | -------------------------------------------------------------------------------- /codebase-0/requirements.txt: -------------------------------------------------------------------------------- 1 | asgiref==3.5.2 2 | Django==4.0.5 3 | sqlparse==0.4.2 4 | -------------------------------------------------------------------------------- /codebase-1/code-base-1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/codebase-1/code-base-1.zip -------------------------------------------------------------------------------- /custom-user-model-ex1/Base.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/Base.zip -------------------------------------------------------------------------------- /custom-user-model-ex1/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/core/__init__.py -------------------------------------------------------------------------------- /custom-user-model-ex1/core/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/core/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/core/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/core/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/core/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/core/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/core/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/core/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/core/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for core 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.0/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", "core.settings") 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /custom-user-model-ex1/core/settings.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 4 | BASE_DIR = Path(__file__).resolve().parent.parent 5 | 6 | 7 | # Quick-start development settings - unsuitable for production 8 | # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ 9 | 10 | # SECURITY WARNING: keep the secret key used in production secret! 11 | SECRET_KEY = "django-insecure-)$hrhngd0d!5(*-r2h1vi)_=gb3p95dd&hi@d1*(^$a$05^y#0" 12 | 13 | # SECURITY WARNING: don't run with debug turned on in production! 14 | DEBUG = True 15 | 16 | ALLOWED_HOSTS = [] 17 | 18 | 19 | # Application definition 20 | 21 | INSTALLED_APPS = [ 22 | "django.contrib.admin", 23 | "django.contrib.auth", 24 | "django.contrib.contenttypes", 25 | "django.contrib.sessions", 26 | "django.contrib.messages", 27 | "django.contrib.staticfiles", 28 | "user", 29 | ] 30 | 31 | MIDDLEWARE = [ 32 | "django.middleware.security.SecurityMiddleware", 33 | "django.contrib.sessions.middleware.SessionMiddleware", 34 | "django.middleware.common.CommonMiddleware", 35 | "django.middleware.csrf.CsrfViewMiddleware", 36 | "django.contrib.auth.middleware.AuthenticationMiddleware", 37 | "django.contrib.messages.middleware.MessageMiddleware", 38 | "django.middleware.clickjacking.XFrameOptionsMiddleware", 39 | ] 40 | 41 | ROOT_URLCONF = "core.urls" 42 | 43 | TEMPLATES = [ 44 | { 45 | "BACKEND": "django.template.backends.django.DjangoTemplates", 46 | "DIRS": [], 47 | "APP_DIRS": True, 48 | "OPTIONS": { 49 | "context_processors": [ 50 | "django.template.context_processors.debug", 51 | "django.template.context_processors.request", 52 | "django.contrib.auth.context_processors.auth", 53 | "django.contrib.messages.context_processors.messages", 54 | ], 55 | }, 56 | }, 57 | ] 58 | 59 | WSGI_APPLICATION = "core.wsgi.application" 60 | 61 | 62 | # Database 63 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 64 | 65 | DATABASES = { 66 | "default": { 67 | "ENGINE": "django.db.backends.sqlite3", 68 | "NAME": BASE_DIR / "db.sqlite3", 69 | } 70 | } 71 | 72 | 73 | # Password validation 74 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 75 | 76 | AUTH_PASSWORD_VALIDATORS = [ 77 | { 78 | "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", 79 | }, 80 | { 81 | "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", 82 | }, 83 | { 84 | "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", 85 | }, 86 | { 87 | "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", 88 | }, 89 | ] 90 | 91 | 92 | # Internationalization 93 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 94 | 95 | LANGUAGE_CODE = "en-us" 96 | 97 | TIME_ZONE = "UTC" 98 | 99 | USE_I18N = True 100 | 101 | USE_TZ = True 102 | 103 | 104 | # Static files (CSS, JavaScript, Images) 105 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ 106 | 107 | STATIC_URL = "static/" 108 | 109 | # Default primary key field type 110 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 111 | 112 | DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" 113 | 114 | AUTH_USER_MODEL = "user.User" 115 | -------------------------------------------------------------------------------- /custom-user-model-ex1/core/urls.py: -------------------------------------------------------------------------------- 1 | """core URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/4.0/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 18 | 19 | urlpatterns = [ 20 | path("admin/", admin.site.urls), 21 | ] 22 | -------------------------------------------------------------------------------- /custom-user-model-ex1/core/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for core 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.0/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", "core.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /custom-user-model-ex1/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/db.sqlite3 -------------------------------------------------------------------------------- /custom-user-model-ex1/manage.py: -------------------------------------------------------------------------------- 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", "core.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() 23 | -------------------------------------------------------------------------------- /custom-user-model-ex1/user/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/user/__init__.py -------------------------------------------------------------------------------- /custom-user-model-ex1/user/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/user/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/user/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/user/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/user/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/user/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/user/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/user/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/user/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | -------------------------------------------------------------------------------- /custom-user-model-ex1/user/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class UserConfig(AppConfig): 5 | default_auto_field = "django.db.models.BigAutoField" 6 | name = "user" 7 | -------------------------------------------------------------------------------- /custom-user-model-ex1/user/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.6 on 2022-07-16 13:47 2 | 3 | import django.contrib.auth.models 4 | import django.contrib.auth.validators 5 | from django.db import migrations, models 6 | import django.utils.timezone 7 | 8 | 9 | class Migration(migrations.Migration): 10 | 11 | initial = True 12 | 13 | dependencies = [ 14 | ("auth", "0012_alter_user_first_name_max_length"), 15 | ] 16 | 17 | operations = [ 18 | migrations.CreateModel( 19 | name="User", 20 | fields=[ 21 | ( 22 | "id", 23 | models.BigAutoField( 24 | auto_created=True, 25 | primary_key=True, 26 | serialize=False, 27 | verbose_name="ID", 28 | ), 29 | ), 30 | ("password", models.CharField(max_length=128, verbose_name="password")), 31 | ( 32 | "last_login", 33 | models.DateTimeField( 34 | blank=True, null=True, verbose_name="last login" 35 | ), 36 | ), 37 | ( 38 | "is_superuser", 39 | models.BooleanField( 40 | default=False, 41 | help_text="Designates that this user has all permissions without explicitly assigning them.", 42 | verbose_name="superuser status", 43 | ), 44 | ), 45 | ( 46 | "username", 47 | models.CharField( 48 | error_messages={ 49 | "unique": "A user with that username already exists." 50 | }, 51 | help_text="Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.", 52 | max_length=150, 53 | unique=True, 54 | validators=[ 55 | django.contrib.auth.validators.UnicodeUsernameValidator() 56 | ], 57 | verbose_name="username", 58 | ), 59 | ), 60 | ( 61 | "first_name", 62 | models.CharField( 63 | blank=True, max_length=150, verbose_name="first name" 64 | ), 65 | ), 66 | ( 67 | "last_name", 68 | models.CharField( 69 | blank=True, max_length=150, verbose_name="last name" 70 | ), 71 | ), 72 | ( 73 | "email", 74 | models.EmailField( 75 | blank=True, max_length=254, verbose_name="email address" 76 | ), 77 | ), 78 | ( 79 | "is_staff", 80 | models.BooleanField( 81 | default=False, 82 | help_text="Designates whether the user can log into this admin site.", 83 | verbose_name="staff status", 84 | ), 85 | ), 86 | ( 87 | "is_active", 88 | models.BooleanField( 89 | default=True, 90 | help_text="Designates whether this user should be treated as active. Unselect this instead of deleting accounts.", 91 | verbose_name="active", 92 | ), 93 | ), 94 | ( 95 | "date_joined", 96 | models.DateTimeField( 97 | default=django.utils.timezone.now, verbose_name="date joined" 98 | ), 99 | ), 100 | ( 101 | "role", 102 | models.CharField( 103 | choices=[ 104 | ("ADMIN", "Admin"), 105 | ("STUDENT", "Student"), 106 | ("TEACHER", "Teacher"), 107 | ], 108 | max_length=50, 109 | ), 110 | ), 111 | ( 112 | "groups", 113 | models.ManyToManyField( 114 | blank=True, 115 | help_text="The groups this user belongs to. A user will get all permissions granted to each of their groups.", 116 | related_name="user_set", 117 | related_query_name="user", 118 | to="auth.group", 119 | verbose_name="groups", 120 | ), 121 | ), 122 | ( 123 | "user_permissions", 124 | models.ManyToManyField( 125 | blank=True, 126 | help_text="Specific permissions for this user.", 127 | related_name="user_set", 128 | related_query_name="user", 129 | to="auth.permission", 130 | verbose_name="user permissions", 131 | ), 132 | ), 133 | ], 134 | options={ 135 | "verbose_name": "user", 136 | "verbose_name_plural": "users", 137 | "abstract": False, 138 | }, 139 | managers=[ 140 | ("objects", django.contrib.auth.models.UserManager()), 141 | ], 142 | ), 143 | ] 144 | -------------------------------------------------------------------------------- /custom-user-model-ex1/user/migrations/0002_student.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.6 on 2022-07-16 13:57 2 | 3 | import django.contrib.auth.models 4 | from django.db import migrations 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ("user", "0001_initial"), 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name="Student", 16 | fields=[], 17 | options={ 18 | "proxy": True, 19 | "indexes": [], 20 | "constraints": [], 21 | }, 22 | bases=("user.user",), 23 | managers=[ 24 | ("objects", django.contrib.auth.models.UserManager()), 25 | ], 26 | ), 27 | ] 28 | -------------------------------------------------------------------------------- /custom-user-model-ex1/user/migrations/0003_teacher.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.6 on 2022-07-16 14:03 2 | 3 | import django.contrib.auth.models 4 | from django.db import migrations 5 | import django.db.models.manager 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ("user", "0002_student"), 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name="Teacher", 17 | fields=[], 18 | options={ 19 | "proxy": True, 20 | "indexes": [], 21 | "constraints": [], 22 | }, 23 | bases=("user.user",), 24 | managers=[ 25 | ("teacher", django.db.models.manager.Manager()), 26 | ("objects", django.contrib.auth.models.UserManager()), 27 | ], 28 | ), 29 | ] 30 | -------------------------------------------------------------------------------- /custom-user-model-ex1/user/migrations/0004_studentprofile.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.6 on 2022-07-16 14:12 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 | ("user", "0003_teacher"), 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name="StudentProfile", 17 | fields=[ 18 | ( 19 | "id", 20 | models.BigAutoField( 21 | auto_created=True, 22 | primary_key=True, 23 | serialize=False, 24 | verbose_name="ID", 25 | ), 26 | ), 27 | ("student_id", models.IntegerField(blank=True, null=True)), 28 | ( 29 | "user", 30 | models.OneToOneField( 31 | on_delete=django.db.models.deletion.CASCADE, 32 | to=settings.AUTH_USER_MODEL, 33 | ), 34 | ), 35 | ], 36 | ), 37 | ] 38 | -------------------------------------------------------------------------------- /custom-user-model-ex1/user/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/user/migrations/__init__.py -------------------------------------------------------------------------------- /custom-user-model-ex1/user/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/user/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/user/migrations/__pycache__/0002_alter_studentprofile_student_id.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/user/migrations/__pycache__/0002_alter_studentprofile_student_id.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/user/migrations/__pycache__/0002_student.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/user/migrations/__pycache__/0002_student.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/user/migrations/__pycache__/0003_teacher.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/user/migrations/__pycache__/0003_teacher.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/user/migrations/__pycache__/0004_studentprofile.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/user/migrations/__pycache__/0004_studentprofile.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/user/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/custom-user-model-ex1/user/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /custom-user-model-ex1/user/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.models import AbstractUser, BaseUserManager 3 | from django.db.models.signals import post_save 4 | from django.dispatch import receiver 5 | 6 | 7 | class User(AbstractUser): 8 | class Role(models.TextChoices): 9 | ADMIN = "ADMIN", "Admin" 10 | STUDENT = "STUDENT", "Student" 11 | TEACHER = "TEACHER", "Teacher" 12 | 13 | base_role = Role.OTHER 14 | 15 | role = models.CharField(max_length=50, choices=Role.choices) 16 | 17 | def save(self, *args, **kwargs): 18 | if not self.pk: 19 | self.role = self.base_role 20 | return super().save(*args, **kwargs) 21 | 22 | 23 | class StudentManager(BaseUserManager): 24 | def get_queryset(self, *args, **kwargs): 25 | results = super().get_queryset(*args, **kwargs) 26 | return results.filter(role=User.Role.STUDENT) 27 | 28 | 29 | class Student(User): 30 | 31 | base_role = User.Role.STUDENT 32 | 33 | student = StudentManager() 34 | 35 | class Meta: 36 | proxy = True 37 | 38 | def welcome(self): 39 | return "Only for students" 40 | 41 | 42 | @receiver(post_save, sender=Student) 43 | def create_user_profile(sender, instance, created, **kwargs): 44 | if created and instance.role == "STUDENT": 45 | StudentProfile.objects.create(user=instance) 46 | 47 | 48 | class StudentProfile(models.Model): 49 | user = models.OneToOneField(User, on_delete=models.CASCADE) 50 | student_id = models.IntegerField(null=True, blank=True) 51 | 52 | 53 | class TeacherManager(BaseUserManager): 54 | def get_queryset(self, *args, **kwargs): 55 | results = super().get_queryset(*args, **kwargs) 56 | return results.filter(role=User.Role.TEACHER) 57 | 58 | 59 | class Teacher(User): 60 | 61 | base_role = User.Role.TEACHER 62 | 63 | teacher = TeacherManager() 64 | 65 | class Meta: 66 | proxy = True 67 | 68 | def welcome(self): 69 | return "Only for teachers" 70 | 71 | 72 | class TeacherProfile(models.Model): 73 | user = models.OneToOneField(User, on_delete=models.CASCADE) 74 | teacher_id = models.IntegerField(null=True, blank=True) 75 | 76 | 77 | @receiver(post_save, sender=Teacher) 78 | def create_user_profile(sender, instance, created, **kwargs): 79 | if created and instance.role == "TEACHER": 80 | TeacherProfile.objects.create(user=instance) 81 | -------------------------------------------------------------------------------- /custom-user-model-ex1/user/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /custom-user-model-ex1/user/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/core/__init__.py -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/core/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/core/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/core/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/core/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/core/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/core/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/core/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/core/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/core/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for core 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.0/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', 'core.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/core/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for core project. 3 | 4 | Generated by 'django-admin startproject' using Django 4.0.6. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/4.0/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/4.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-(9yt28f(r(4o^p8n!ts^grj$ic&^2l2yw*67d!3=rjhte=4bzb' 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 | 'user' 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 = 'core.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 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 = 'core.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': BASE_DIR / 'db.sqlite3', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_TZ = True 114 | 115 | 116 | # Static files (CSS, JavaScript, Images) 117 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ 118 | 119 | STATIC_URL = 'static/' 120 | 121 | # Default primary key field type 122 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 123 | 124 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 125 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/core/urls.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from django.urls import path, include 3 | 4 | urlpatterns = [ 5 | path('admin/', admin.site.urls), 6 | path('', include("user.urls", namespace="user")) 7 | ] 8 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/core/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for core 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.0/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', 'core.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/db.sqlite3 -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/manage.py: -------------------------------------------------------------------------------- 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', 'core.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() 23 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/requirements.txt: -------------------------------------------------------------------------------- 1 | asgiref==3.5.2 2 | Django==4.0.6 3 | Pillow==9.2.0 4 | sqlparse==0.4.2 5 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/user/__init__.py -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/user/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/user/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/user/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/user/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/user/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/__pycache__/views.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/user/__pycache__/views.cpython-39.pyc -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from user.models import UserProfile 4 | from django.contrib.auth.models import User 5 | from django.contrib.auth.admin import UserAdmin as AuthUserAdmin 6 | 7 | class UserProfileInline(admin.StackedInline): 8 | model = UserProfile 9 | can_delete = False 10 | 11 | class AccountsUserAdmin(AuthUserAdmin): 12 | def add_view(self, *args, **kwargs): 13 | self.inlines =[] 14 | return super(AccountsUserAdmin, self).add_view(*args, **kwargs) 15 | 16 | def change_view(self, *args, **kwargs): 17 | self.inlines =[UserProfileInline] 18 | return super(AccountsUserAdmin, self).change_view(*args, **kwargs) 19 | 20 | 21 | admin.site.unregister(User) 22 | admin.site.register(User, AccountsUserAdmin) 23 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | from django.contrib.auth import get_user_model 3 | 4 | 5 | class UserConfig(AppConfig): 6 | default_auto_field = 'django.db.models.BigAutoField' 7 | name = 'user' 8 | 9 | def sayhi(self): 10 | print("hiya") 11 | 12 | def ready(self): 13 | User = get_user_model() 14 | User.sayhi = self.sayhi -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/fixtures/db_admin_fixture.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "auth.user", 4 | "pk": 1, 5 | "fields": { 6 | "username": "admin", 7 | "password": "pbkdf2_sha256$260000$KfZ2hspAeA8KhAAJ8mKpjw$60ajS7y4Fw72yg+DzZQADfUsUs4l3MJuhABupfjQ3z0=", 8 | "email": "a@a.com", 9 | "is_superuser": true, 10 | "is_staff": true, 11 | "is_active": true 12 | } 13 | }, 14 | { 15 | "model": "auth.user", 16 | "pk": 2, 17 | "fields": { 18 | "username": "student1", 19 | "password": "pbkdf2_sha256$260000$KfZ2hspAeA8KhAAJ8mKpjw$60ajS7y4Fw72yg+DzZQADfUsUs4l3MJuhABupfjQ3z0=", 20 | "email": "1@1.com", 21 | "first_name": "astudent", 22 | "is_active": true 23 | } 24 | }, 25 | { 26 | "model": "auth.user", 27 | "pk": 3, 28 | "fields": { 29 | "username": "student2", 30 | "password": "pbkdf2_sha256$260000$KfZ2hspAeA8KhAAJ8mKpjw$60ajS7y4Fw72yg+DzZQADfUsUs4l3MJuhABupfjQ3z0=", 31 | "email": "2@2.com", 32 | "first_name": "cstudent", 33 | "is_active": true 34 | } 35 | }, 36 | { 37 | "model": "auth.user", 38 | "pk": 4, 39 | "fields": { 40 | "username": "student3", 41 | "password": "pbkdf2_sha256$260000$KfZ2hspAeA8KhAAJ8mKpjw$60ajS7y4Fw72yg+DzZQADfUsUs4l3MJuhABupfjQ3z0=", 42 | "email": "3@3.com", 43 | "first_name": "bstudent", 44 | "is_active": true 45 | } 46 | }, 47 | { 48 | "model": "auth.user", 49 | "pk": 5, 50 | "fields": { 51 | "username": "student4", 52 | "password": "pbkdf2_sha256$260000$KfZ2hspAeA8KhAAJ8mKpjw$60ajS7y4Fw72yg+DzZQADfUsUs4l3MJuhABupfjQ3z0=", 53 | "email": "4@4.com", 54 | "first_name": "dstudent", 55 | "is_active": false 56 | } 57 | } 58 | ] 59 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.0.6 on 2022-07-12 12:55 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 | initial = True 11 | 12 | dependencies = [ 13 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 14 | ] 15 | 16 | operations = [ 17 | migrations.CreateModel( 18 | name='UserProfile', 19 | fields=[ 20 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 21 | ('age', models.IntegerField(blank=True, null=True)), 22 | ('nickname', models.CharField(blank=True, max_length=100, null=True)), 23 | ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 24 | ], 25 | ), 26 | ] 27 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/user/migrations/__init__.py -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/user/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/Django-4.x-ORM-Course/1db8964636fcd05a78e5f27723862d71a91d9a61/customer-user-model-add-user-fields/user/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.contrib.auth.admin import User 3 | from django.dispatch import receiver 4 | from django.db.models.signals import post_save 5 | 6 | class UserProfile(models.Model): 7 | user = models.OneToOneField(User, on_delete=models.CASCADE) 8 | age = models.IntegerField(null=True, blank=True) 9 | nickname = models.CharField(max_length=100, null=True, blank=True) 10 | 11 | def __str__(self): 12 | return self.user.username 13 | 14 | @receiver(post_save, sender=User) 15 | def create_user_profile(sender, instance, created, **kwargs): 16 | if created: 17 | UserProfile.objects.create(user=instance) 18 | 19 | # class PersonManagerInactive(models.Manager): 20 | # def get_queryset(self): 21 | # return super(PersonManagerInactive, self).get_queryset().filter(is_active=False) 22 | 23 | # class PersonManagerActive(models.Manager): 24 | # def get_queryset(self): 25 | # return super(PersonManagerActive, self).get_queryset().filter(is_active=True) 26 | 27 | # class Person(User): 28 | 29 | # inactive = PersonManagerInactive() 30 | # active = PersonManagerActive() 31 | 32 | # class Meta: 33 | # proxy = True 34 | # ordering = ('first_name',) 35 | 36 | # @classmethod 37 | # def count_all(cls,): 38 | # return cls.objects.filter(is_active=True).count() 39 | 40 | # def check_active(self): 41 | # if self.is_active == True: 42 | # return "You are Active!" 43 | # else: 44 | # return "You are not Active!" 45 | 46 | # def __str__(self): 47 | # return self.first_name 48 | 49 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/templates/profile.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Bootstrap demo 7 | 8 | 9 | 10 | 11 |
12 |
13 |
14 | {% csrf_token %} 15 | {{ u_form.as_p}} 16 | {{ p_form.as_p}} 17 | 18 |
19 |
20 |
21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | app_name = "user" 5 | 6 | urlpatterns = [ 7 | path("profile/", views.update_profile, name='profile') 8 | ] 9 | -------------------------------------------------------------------------------- /customer-user-model-add-user-fields/user/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render, redirect 2 | from django import forms 3 | from .models import UserProfile 4 | from django.contrib.auth.models import User 5 | from django.db import transaction 6 | from django.contrib.auth.decorators import login_required 7 | 8 | class UserForm(forms.ModelForm): 9 | class Meta: 10 | model = User 11 | fields = ("first_name", "last_name") 12 | 13 | class UserProfileForm(forms.ModelForm): 14 | class Meta: 15 | model = UserProfile 16 | fields = ("age", "nickname") 17 | 18 | @login_required 19 | @transaction.atomic 20 | def update_profile(request): 21 | if request.method == "POST": 22 | user_form = UserForm(request.POST, instance=request.user) 23 | user_profile_form = UserProfileForm(request.POST, instance=request.user.userprofile) 24 | if user_form.is_valid() and user_profile_form.is_valid(): 25 | user_form.save() 26 | user_profile_form.save() 27 | return redirect("user:profile") 28 | else: 29 | user_form = UserForm(instance=request.user) 30 | user_profile_form = UserProfileForm(instance=request.user.userprofile) 31 | return render(request, "profile.html", {"u_form":user_form, "p_form": user_profile_form}) 32 | --------------------------------------------------------------------------------