Created CustomUser and tweaked backend models.
This commit is contained in:
parent
5175646e51
commit
bd1bf44059
12 changed files with 59 additions and 138 deletions
|
@ -1,126 +0,0 @@
|
|||
# Generated by Django 2.1.4 on 2019-01-20 22:35
|
||||
|
||||
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='DataBool',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('data', models.BooleanField()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='DataDate',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('data', models.DateField()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='DataDecimal',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('data', models.DecimalField(decimal_places=2, max_digits=9)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='DataFile',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('data', models.FileField(upload_to='')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='DataInteger',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('data', models.IntegerField()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='DataString',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('data', models.TextField()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Field',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('label', models.CharField(max_length=256)),
|
||||
('number', models.IntegerField()),
|
||||
('type', models.CharField(max_length=128)),
|
||||
('completed', models.BooleanField()),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Report',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=128)),
|
||||
('date_created', models.DateTimeField(verbose_name='date created')),
|
||||
('date_submitted', models.DateTimeField(verbose_name='date submitted')),
|
||||
('submitted', models.BooleanField()),
|
||||
('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Section',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('completed', models.BooleanField()),
|
||||
('title', models.CharField(max_length=256)),
|
||||
('html_description', models.TextField()),
|
||||
('number', models.IntegerField()),
|
||||
('report_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Report')),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='field',
|
||||
name='section_id',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Section'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='datastring',
|
||||
name='field_id',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Field'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='datainteger',
|
||||
name='field_id',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Field'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='datafile',
|
||||
name='field_id',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Field'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='datadecimal',
|
||||
name='field_id',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Field'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='datadate',
|
||||
name='field_id',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Field'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='databool',
|
||||
name='field_id',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='backend.Field'),
|
||||
),
|
||||
]
|
|
@ -1,12 +1,12 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.conf import settings
|
||||
|
||||
class Report(models.Model):
|
||||
user_id = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
user_id = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
title = models.CharField(max_length=128)
|
||||
date_created = models.DateTimeField('date created')
|
||||
date_submitted = models.DateTimeField('date submitted')
|
||||
submitted = models.BooleanField()
|
||||
date_submitted = models.DateTimeField('date submitted', null=True, blank=True)
|
||||
submitted = models.BooleanField(default=False)
|
||||
|
||||
class Section(models.Model):
|
||||
report_id = models.ForeignKey(Report, on_delete=models.CASCADE)
|
||||
|
@ -20,28 +20,28 @@ class Field(models.Model):
|
|||
label = models.CharField(max_length=256)
|
||||
number = models.IntegerField()
|
||||
type = models.CharField(max_length=128)
|
||||
completed = models.BooleanField()
|
||||
completed = models.BooleanField(default=False)
|
||||
|
||||
class DataBool(models.Model):
|
||||
field_id = models.ForeignKey(Field, on_delete=models.CASCADE)
|
||||
data = models.BooleanField()
|
||||
data = models.BooleanField(default=False)
|
||||
|
||||
class DataDecimal(models.Model):
|
||||
field_id = models.ForeignKey(Field, on_delete=models.CASCADE)
|
||||
data = models.DecimalField(max_digits=9,decimal_places=2)
|
||||
data = models.DecimalField(max_digits=9,decimal_places=2, null=True, blank=True)
|
||||
|
||||
class DataDate(models.Model):
|
||||
field_id = models.ForeignKey(Field, on_delete=models.CASCADE)
|
||||
data = models.DateField()
|
||||
data = models.DateField(null=True, blank=True)
|
||||
|
||||
class DataFile(models.Model):
|
||||
field_id = models.ForeignKey(Field, on_delete=models.CASCADE)
|
||||
data = models.FileField()
|
||||
data = models.FileField(null=True, blank=True)
|
||||
|
||||
class DataString(models.Model):
|
||||
field_id = models.ForeignKey(Field, on_delete=models.CASCADE)
|
||||
data = models.TextField()
|
||||
data = models.TextField(default='')
|
||||
|
||||
class DataInteger(models.Model):
|
||||
field_id = models.ForeignKey(Field, on_delete=models.CASCADE)
|
||||
data = models.IntegerField()
|
||||
data = models.IntegerField(null=True, blank=True)
|
||||
|
|
BIN
back/db.sqlite3
BIN
back/db.sqlite3
Binary file not shown.
|
@ -39,6 +39,7 @@ INSTALLED_APPS = [
|
|||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'backend',
|
||||
'users',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -82,6 +83,9 @@ DATABASES = {
|
|||
}
|
||||
}
|
||||
|
||||
# Authentication
|
||||
|
||||
AUTH_USER_MODEL = 'users.CustomUser'
|
||||
|
||||
# Password validation
|
||||
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
|
||||
|
|
0
back/users/__init__.py
Normal file
0
back/users/__init__.py
Normal file
12
back/users/admin.py
Normal file
12
back/users/admin.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
|
||||
from .forms import CustomUserCreationForm, CustomUserChangeForm
|
||||
from .models import CustomUser
|
||||
|
||||
class CustomUserAdmin(UserAdmin):
|
||||
add_form = CustomUserCreationForm
|
||||
form = CustomUserChangeForm
|
||||
model = CustomUser
|
||||
|
||||
admin.site.register(CustomUser, CustomUserAdmin)
|
5
back/users/apps.py
Normal file
5
back/users/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class UsersConfig(AppConfig):
|
||||
name = 'users'
|
15
back/users/forms.py
Normal file
15
back/users/forms.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from django import forms
|
||||
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
|
||||
|
||||
from .models import CustomUser
|
||||
|
||||
class CustomUserCreationForm(UserCreationForm):
|
||||
class Meta(UserCreationForm):
|
||||
model = CustomUser
|
||||
fields = UserCreationForm.Meta.fields + ('age',)
|
||||
|
||||
class CustomUserChangeForm(UserChangeForm):
|
||||
|
||||
class Meta:
|
||||
model = CustomUser
|
||||
fields = UserChangeForm.Meta.fields
|
0
back/users/migrations/__init__.py
Normal file
0
back/users/migrations/__init__.py
Normal file
5
back/users/models.py
Normal file
5
back/users/models.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from django.contrib.auth.models import AbstractUser
|
||||
from django.db import models
|
||||
|
||||
class CustomUser(AbstractUser):
|
||||
age = models.PositiveIntegerField(null=True, blank=True)
|
3
back/users/tests.py
Normal file
3
back/users/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
back/users/views.py
Normal file
3
back/users/views.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
Loading…
Reference in a new issue