BES-15 Created django project with new db table StudentProfile which extends User Model using a One-To-One link.

This commit is contained in:
ksanu 2019-11-25 00:10:39 +01:00
commit 9ae175554c
32 changed files with 585 additions and 0 deletions

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/BestNotesProject.iml" filepath="$PROJECT_DIR$/.idea/BestNotesProject.iml" />
</modules>
</component>
</project>

281
.idea/workspace.xml Normal file
View File

@ -0,0 +1,281 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="b23c009e-2f8a-48f7-8b29-023f93596932" name="Default Changelist" comment="" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/BestNotesProject/urls.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="22" selection-start-line="22" selection-end-line="22" />
<folding>
<element signature="e#640#672#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/bestnotes/urls.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="5" column="37" selection-start-line="5" selection-start-column="37" selection-end-line="5" selection-end-column="37" />
<folding>
<element signature="e#0#28#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/bestnotes/views.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="7" column="55" selection-start-line="7" selection-start-column="55" selection-end-line="7" selection-end-column="55" />
<folding>
<element signature="e#0#35#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/bestnotes/models.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="88">
<caret line="17" column="21" lean-forward="true" selection-start-line="17" selection-start-column="21" selection-end-line="17" selection-end-column="21" />
<folding>
<element signature="e#0#28#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/bestnotes/admin.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
<caret line="6" column="34" selection-start-line="6" selection-start-column="34" selection-end-line="6" selection-end-column="34" />
<folding>
<element signature="e#0#32#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/BestNotesProject/settings.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="33" column="37" selection-start-line="33" selection-start-column="37" selection-end-line="33" selection-end-column="37" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>bestnotes.apps.BestnotesConfigdjango</find>
</findStrings>
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/BestNotesProject/urls.py" />
<option value="$PROJECT_DIR$/bestnotes/urls.py" />
<option value="$PROJECT_DIR$/bestnotes/views.py" />
<option value="$PROJECT_DIR$/BestNotesProject/settings.py" />
<option value="$PROJECT_DIR$/bestnotes/admin.py" />
<option value="$PROJECT_DIR$/bestnotes/models.py" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="1">
<option name="x" value="377" />
<option name="y" value="92" />
<option name="width" value="1324" />
<option name="height" value="1000" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="BestNotesProject" type="b2602c69:ProjectViewProjectNode" />
<item name="BestNotesProject" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="BestNotesProject" type="b2602c69:ProjectViewProjectNode" />
<item name="BestNotesProject" type="462c0819:PsiDirectoryNode" />
<item name="bestnotes" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="BestNotesProject" type="b2602c69:ProjectViewProjectNode" />
<item name="BestNotesProject" type="462c0819:PsiDirectoryNode" />
<item name="bestnotes" type="462c0819:PsiDirectoryNode" />
<item name="migrations" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="BestNotesProject" type="b2602c69:ProjectViewProjectNode" />
<item name="BestNotesProject" type="462c0819:PsiDirectoryNode" />
<item name="BestNotesProject" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="preferences.general" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="b23c009e-2f8a-48f7-8b29-023f93596932" name="Default Changelist" comment="" />
<created>1574623676973</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1574623676973</updated>
</task>
<servers />
</component>
<component name="ToolWindowManager">
<frame x="302" y="74" width="1059" height="800" extended-state="0" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.20136853" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Version Control" order="7" />
<window_info anchor="bottom" id="Terminal" order="8" visible="true" weight="0.32884902" />
<window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
<window_info anchor="bottom" id="Python Console" order="10" weight="0.32884902" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/BestNotesProject/urls.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="22" selection-start-line="22" selection-end-line="22" />
<folding>
<element signature="e#640#672#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/bestnotes/urls.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="5" column="37" selection-start-line="5" selection-start-column="37" selection-end-line="5" selection-end-column="37" />
<folding>
<element signature="e#0#28#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/bestnotes/views.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="7" column="55" selection-start-line="7" selection-start-column="55" selection-end-line="7" selection-end-column="55" />
<folding>
<element signature="e#0#35#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://D:/Programming/Python/Python_3.8/Lib/site-packages/django/apps/config.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="140">
<caret line="115" selection-start-line="115" selection-end-line="115" />
</state>
</provider>
</entry>
<entry file="file://D:/Programming/Python/Python_3.8/Lib/importlib/__init__.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="140">
<caret line="126" selection-start-line="126" selection-end-line="126" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/bestnotes/apps.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="85">
<caret line="5" lean-forward="true" selection-start-line="5" selection-end-line="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/BestNotesProject/settings.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="33" column="37" selection-start-line="33" selection-start-column="37" selection-end-line="33" selection-end-column="37" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/bestnotes/admin.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
<caret line="6" column="34" selection-start-line="6" selection-start-column="34" selection-end-line="6" selection-end-column="34" />
<folding>
<element signature="e#0#32#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/bestnotes/models.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="88">
<caret line="17" column="21" lean-forward="true" selection-start-line="17" selection-start-column="21" selection-end-line="17" selection-end-column="21" />
<folding>
<element signature="e#0#28#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
</project>

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,121 @@
"""
Django settings for BestNotesProject project.
Generated by 'django-admin startproject' using Django 2.2.7.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '!_d^j-tap#j_d+hqaz^g8*n4l-p=uop+5s-jbiykp2_6ik-xwa'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'bestnotes.apps.BestnotesConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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',
]
ROOT_URLCONF = 'BestNotesProject.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 = 'BestNotesProject.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.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/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'

22
BestNotesProject/urls.py Normal file
View File

@ -0,0 +1,22 @@
"""BestNotesProject URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.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
urlpatterns = [
path('bestnotes/', include('bestnotes.urls')),
path('admin/', admin.site.urls),
]

16
BestNotesProject/wsgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
WSGI config for BestNotesProject 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/2.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BestNotesProject.settings')
application = get_wsgi_application()

0
bestnotes/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

7
bestnotes/admin.py Normal file
View File

@ -0,0 +1,7 @@
from django.contrib import admin
# Register your models here.
from django.contrib import admin
from .models import StudentProfile
admin.site.register(StudentProfile)

5
bestnotes/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class BestnotesConfig(AppConfig):
name = 'bestnotes'

View File

@ -0,0 +1,27 @@
# Generated by Django 2.2.7 on 2019-11-24 22:36
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='StudentProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('bio', models.TextField(blank=True, max_length=500)),
('birth_date', models.DateField(blank=True, null=True)),
('location', models.CharField(blank=True, max_length=100)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]

View File

35
bestnotes/models.py Normal file
View File

@ -0,0 +1,35 @@
from django.db import models
# Create your models here.
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
class StudentProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
#Custom filds extending default user table:
bio = models.TextField(max_length=500, blank=True)
birth_date = models.DateField(null=True, blank=True)
#student_name = models.TextField(max_length=50, blank=True) #User table has first_name fild
#student_surname = models.TextField(max_length=50, blank=True) #User table has last_name field
location = models.CharField(max_length=100, blank=True)#can contain info about country, city, school etc.
"""
to add as foreign key, when coresponding table is added:
CourseId
"""
@receiver(post_save, sender=User)
def create_studentprofile(sender, instance, created, **kwargs):
if created:
StudentProfile.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_studentprofile(sender, instance, **kwargs):
instance.studentprofile.save()

3
bestnotes/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

7
bestnotes/urls.py Normal file
View File

@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index')
]

8
bestnotes/views.py Normal file
View File

@ -0,0 +1,8 @@
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse("BestNotes' index will be here.")

6
bn_migrate_log.txt Normal file
View File

@ -0,0 +1,6 @@
BEGIN;
--
-- Create model StudentProfile
--
CREATE TABLE "bestnotes_studentprofile" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "bio" text NOT NULL, "birth_date" date NULL, "location" varchar(100) NOT NULL, "user_id" integer NOT NULL UNIQUE REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED);
COMMIT;

BIN
db.sqlite3 Normal file

Binary file not shown.

21
manage.py Normal file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BestNotesProject.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()