Commit a29d0aaf authored by Борис Ким's avatar Борис Ким

Создал модели и применил миграции. Добавил приложение в настройки

parent 2940da73
"""
Django settings for portal project.
Generated by 'django-admin startproject' using Django 3.2.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
......@@ -37,6 +27,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'webapp'
]
MIDDLEWARE = [
......@@ -123,3 +114,7 @@ STATIC_URL = '/static/'
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
\ No newline at end of file
# Generated by Django 3.2.8 on 2021-10-30 16:52
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='Specialization',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('spec_name', models.CharField(max_length=100, verbose_name='spec_name')),
],
),
migrations.CreateModel(
name='Group',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('group_name', models.CharField(max_length=50, verbose_name='group_name')),
('specialization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='webapp.specialization', verbose_name='specialization')),
('students', models.ManyToManyField(related_name='students', to=settings.AUTH_USER_MODEL, verbose_name='students')),
],
),
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50, verbose_name='title')),
('description', models.TextField(max_length=2000, verbose_name='description')),
('start_date', models.DateField(verbose_name='Start date')),
('group', models.ManyToManyField(related_name='groups', to='webapp.Group', verbose_name='group')),
('teacher', models.ForeignKey(default=1, on_delete=django.db.models.deletion.SET_DEFAULT, to=settings.AUTH_USER_MODEL, verbose_name='teacher')),
],
),
migrations.CreateModel(
name='Class',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=100, verbose_name='title')),
('description', models.TextField(max_length=2000, verbose_name='description')),
('file', models.FileField(upload_to='uploads/')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('course', models.ManyToManyField(related_name='courses', to='webapp.Course', verbose_name='course')),
],
),
]
from django.db import models
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
# Create your models here.
# class Student(User):
# name = models.CharField(max_length=50, verbose_name='name')
# surname = models.CharField(max_length=50, verbose_name='name')
# group = models.ForeignKey('webapp.Group', on_delete=models.CASCADE, verbose_name='group')
# course = models.ManyToManyField('webapp.Course', verbose_name='course', related_name='courses')
# adviser = models.ForeignKey('webapp.Teacher', on_delete=models.CASCADE, verbose_name='adviser')
# admission_date = models.DateField(('Admission date'), auto_now=False, auto_now_add=False)
# end_date = models.DateField(('End date'), auto_now=False, auto_now_add=False)
# class Teacher(models.Model):
# name = models.CharField(max_length=50, verbose_name='name')
# surname = models.CharField(max_length=50, verbose_name='name')
class Course(models.Model):
title = models.CharField(max_length=50, verbose_name='title')
description = models.TextField(max_length=2000, verbose_name='description')
group = models.ManyToManyField('webapp.Group', verbose_name='group', related_name='groups')
teacher = models.ForeignKey(get_user_model(), on_delete=models.SET_DEFAULT, verbose_name='teacher', default=1)
start_date = models.DateField(('Start date'), auto_now=False, auto_now_add=False)
def __str__(self):
return self.title
class Group(models.Model):
group_name = models.CharField(max_length=50, verbose_name='group_name')
specialization = models.ForeignKey('webapp.Specialization', on_delete=models.CASCADE, verbose_name='specialization')
students = models.ManyToManyField(get_user_model(), verbose_name='students', related_name='students')
def __str__(self):
return self.group_name
class Class(models.Model):
title = models.CharField(max_length=100, verbose_name='title')
description = models.TextField(max_length=2000, verbose_name='description')
file = models.FileField(upload_to='uploads/')
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
course = models.ManyToManyField('webapp.Course', verbose_name='course', related_name='courses')
def __str__(self):
return self.title
class Specialization(models.Model):
spec_name = models.CharField(max_length=100, verbose_name='spec_name')
def __str__(self):
return self.spec_name
\ No newline at end of file
from django.shortcuts import render
# Create your views here.
def view(request):
return render(request, 'courses.html')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment