Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions 2205126/Django_demo_app/Documentation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
django-admin startproject <projectname>:
command used to initialise a project in django

python manage.py runserver or django-admin runserver:
command used to start the Django development server. It allows you to run your Django application locally for testing and development purposes.

python manage.py startapp <appname>:
command used to create apps.

.vscode/launch.json :
includes debugging configurations for views.py

Using django-debug-toolbar for debugging (Alternative for vscode direct debugging):
requires installation using 'pip install django-debug-toolbar'
requires a proper html response to work
reference docs: https://django-debug-toolbar.readthedocs.io/en/latest/installation.html
settings.py should be modified to include the following:
INSTALLED_APPS = [
...
'debug_toolbar',
...
]
MIDDLEWARE = [
...
'debug_toolbar.middleware.DebugToolbarMiddleware',
...
]
DEBUG = True
INTERNAL_IPS = [
#...
'127.0.0.1',
#...
]

/*
What is migrations?
Each migration describes a set of changes, similar to commits in version control systems
*/

python manage.py makemigrations :
creates migrations for all the installed apps in the project, these files are used when migrating from development to production server,
.py code in these files will be converted MYSQL statements for creating tables and database

python manage.py migrate :
command to run migrations

/*
vscode extension named "SQLite" for using and opening SQLite databases in vscde"
*/

python manage.py sqlmigrate "name of migration (eg: store 0003)" :
displays actual code/sql-statements that are sent to our database during migration
the type of statements that are sent depends on the backend database that is used (eg: SQLite, MYSQL, PostgresSQL etc)

python manage.py migrate "name of the migration to which you want to revert to" :
reverts the migration to the specified migration file

pip install mysqlclient :
for using mysql database
also mysql server is required to be downloaded, if mysql workbench is installed than no need to install mysql server separately.

errors encountered while installing:
error: subprocess-exited-with-error :
occurs if libmysqlclient-dev build-essential is not installed, which are dependencies for installing mysqlclient
resolve by installing: sudo apt install libmysqlclient-dev build-essential

settings.py should be modified to include the following in DATABASE:
To use environment variables import os.environ
DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "storefront",
"HOST": "localhost",
"USER": "root",
"PASSWORD": environ.get("DATABASE_PASSWORD"),
}
}


python manage.py makemigrations store --empty :
# This command is used to create an empty migration file for the 'store' app in Django.
# The 'makemigrations' command is used to generate database migration files based on changes in the models.
# The '--empty' flag indicates that the migration file should be empty, without any changes to the database schema.
# This command is useful when you want to manually write the migration file instead of relying on Django's automatic migration generation.
Empty file.
16 changes: 16 additions & 0 deletions 2205126/Django_demo_app/Note_maker/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for Note_maker project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Note_maker.settings")

application = get_asgi_application()
137 changes: 137 additions & 0 deletions 2205126/Django_demo_app/Note_maker/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
"""
Django settings for Note_maker project.

Generated by 'django-admin startproject' using Django 4.2.10.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

from pathlib import Path
from os import environ
from django.utils import timezone

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "django-insecure-4h)&t8&z#tjqpuugsh1-yoddditqs)od62u052jat(&i(c8o0a"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
'debug_toolbar',
'notes_app',
]

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
'debug_toolbar.middleware.DebugToolbarMiddleware',
]

INTERNAL_IPS = [
#...
'127.0.0.1',
#...
]

ROOT_URLCONF = "Note_maker.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]

WSGI_APPLICATION = "Note_maker.wsgi.application"


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"NAME": "note_maker",
"HOST": "localhost",
"USER": "root",
"PASSWORD": environ.get("DATABASE_PASSWORD"),
}
}


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "Asia/Kolkata"

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = "static/"

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
25 changes: 25 additions & 0 deletions 2205126/Django_demo_app/Note_maker/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
URL configuration for Note_maker project.

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/4.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
import debug_toolbar

urlpatterns = [
path("admin/", admin.site.urls),
path("__debug__/", include(debug_toolbar.urls)),
path("", include("notes_app.urls")),
]
16 changes: 16 additions & 0 deletions 2205126/Django_demo_app/Note_maker/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for Note_maker project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Note_maker.settings")

application = get_wsgi_application()
Empty file.
22 changes: 22 additions & 0 deletions 2205126/Django_demo_app/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Note_maker.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
Empty file.
3 changes: 3 additions & 0 deletions 2205126/Django_demo_app/notes_app/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions 2205126/Django_demo_app/notes_app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class NotesAppConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "notes_app"
31 changes: 31 additions & 0 deletions 2205126/Django_demo_app/notes_app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 4.2.10 on 2024-02-29 10:45

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="note",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(max_length=200)),
("content", models.TextField()),
("created_at", models.DateTimeField(auto_now_add=True)),
("last_modified", models.DateTimeField(auto_now=True)),
],
),
]
Empty file.
9 changes: 9 additions & 0 deletions 2205126/Django_demo_app/notes_app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.db import models
from datetime import datetime
# Create your models here.

class note(models.Model):
title = models.CharField(max_length=200, null=False)
content = models.TextField(null=False)
created_at = models.DateTimeField(auto_now_add=True)
last_modified = models.DateTimeField(auto_now=True)
Loading