add initial models

This commit is contained in:
Maxime Bloch 2020-07-21 22:24:45 +02:00
parent 56ab57f7f5
commit d0ff75f2c6
14 changed files with 129 additions and 4 deletions

3
.gitignore vendored
View file

@ -1,2 +1,5 @@
venv/
.idea/
**/__pycache__/**
*.sqlite3
*.pyc

View file

@ -30,6 +30,11 @@ ALLOWED_HOSTS = []
# Application definition
OWN_APPS = [
'events',
'users'
]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
@ -37,7 +42,9 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
] + OWN_APPS
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
@ -76,8 +83,12 @@ WSGI_APPLICATION = 'KeRS.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'django.db.backends.mysql',
'NAME': 'kers',
'USER': 'kers',
'PASSWORD': 'kers',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}

View file

@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include
urlpatterns = [
path('events/', include('events.urls')),
path('admin/', admin.site.urls),
]

3
events/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
events/apps.py Normal file
View file

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

View file

@ -0,0 +1,33 @@
# Generated by Django 3.0.8 on 2020-07-21 20:00
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('users', '__first__'),
]
operations = [
migrations.CreateModel(
name='Event',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date', models.DateTimeField()),
('capacity', models.IntegerField()),
],
),
migrations.CreateModel(
name='EventRegistration',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('shirt_size', models.CharField(choices=[('I', 'Interested'), ('A', 'Admitted'), ('D', 'Denied')], max_length=1)),
('event_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.Event')),
('user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.User')),
],
),
]

View file

View file

@ -0,0 +1,19 @@
from django.db import models
from users.models import User
class Event(models.Model):
date = models.DateTimeField()
capacity = models.IntegerField()
class EventRegistration(models.Model):
REGISTRATION_STATE = (
('I', 'Interested'),
('A', 'Admitted'),
('D', 'Denied'),
)
event_id = models.ForeignKey(Event, on_delete=models.CASCADE)
user_id = models.ForeignKey(User, on_delete=models.CASCADE)
shirt_size = models.CharField(max_length=1, choices=REGISTRATION_STATE)

3
events/tests.py Normal file
View file

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

7
events/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
events/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("Hello, world. You're at the polls index.")

View file

@ -0,0 +1,24 @@
# Generated by Django 3.0.8 on 2020-07-21 20:03
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('zeus_id', models.IntegerField()),
('username', models.CharField(max_length=255)),
('student_number', models.CharField(max_length=255)),
('real_name', models.CharField(max_length=255)),
],
),
]

View file

View file

@ -0,0 +1,8 @@
from django.db import models
class User(models.Model):
zeus_id = models.IntegerField()
username = models.CharField(max_length=255) # zeus username
student_number = models.CharField(max_length=255)
real_name = models.CharField(max_length=255)