From a4325359973537c3950e4f1cb0c7e93bd58dc4cb Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 12 Sep 2018 15:42:04 -0600 Subject: [PATCH] Create first DB migrations and remove uuid --- .../authserver/api/migrations/0001_initial.py | 55 +++++++++++++++++++ authserver/authserver/api/models.py | 6 +- 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 authserver/authserver/api/migrations/0001_initial.py diff --git a/authserver/authserver/api/migrations/0001_initial.py b/authserver/authserver/api/migrations/0001_initial.py new file mode 100644 index 0000000..54f8228 --- /dev/null +++ b/authserver/authserver/api/migrations/0001_initial.py @@ -0,0 +1,55 @@ +# Generated by Django 2.1.1 on 2018-09-12 21:41 + +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='Category', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=32)), + ('slug', models.CharField(max_length=32)), + ('info', models.TextField(blank=True, max_length=1024)), + ('photo', models.FileField(upload_to='media/')), + ], + ), + migrations.CreateModel( + name='Profile', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('lockout_admin', models.BooleanField(default=False)), + ], + ), + migrations.CreateModel( + name='Tool', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=32)), + ('info', models.TextField(blank=True, max_length=1024)), + ('wiki_id', models.IntegerField()), + ('photo', models.FileField(upload_to='media/')), + ('category', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='tools', to='api.Category')), + ], + ), + migrations.AddField( + model_name='profile', + name='authorized_tools', + field=models.ManyToManyField(to='api.Tool'), + ), + migrations.AddField( + model_name='profile', + name='user', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/authserver/authserver/api/models.py b/authserver/authserver/api/models.py index 3962a2b..fa6bdb0 100644 --- a/authserver/authserver/api/models.py +++ b/authserver/authserver/api/models.py @@ -1,3 +1,4 @@ +from django.contrib.auth.models import User from django.db import models class Category(models.Model): @@ -7,14 +8,13 @@ class Category(models.Model): photo = models.FileField(upload_to='media/') class Tool(models.Model): - uuid = models.UUIDField(default=uuid.uuid4, editable=False) - category = models.ForeignKey(Category, related_name='tools') + category = models.ForeignKey(Category, related_name='tools', on_delete=models.PROTECT) name = models.CharField(max_length=32) info = models.TextField(max_length=1024, blank=True) wiki_id = models.IntegerField() photo = models.FileField(upload_to='media/') class Profile(models.Model): - user = models.OneToOneField(User) + user = models.OneToOneField(User, on_delete=models.CASCADE) lockout_admin = models.BooleanField(default=False) authorized_tools = models.ManyToManyField(Tool)