Added models for Cafeteria, Location, Institution

This commit is contained in:
Maximilian Giller 2024-02-28 21:26:34 +01:00
parent f7a631d543
commit cdd4a01521
13 changed files with 161 additions and 4 deletions

View file

@ -1,6 +1,12 @@
from django.contrib import admin
from api_v1.profile.profile import Profile
from api_v1.cafeteria.model import Cafeteria
from api_v1.institution.model import Institution
from api_v1.location.model import Location
from api_v1.profile.model import Profile
# Register your models here.
admin.site.register(Profile)
admin.site.register(Location)
admin.site.register(Cafeteria)
admin.site.register(Institution)

View file

19
api_v1/cafeteria/model.py Normal file
View file

@ -0,0 +1,19 @@
import uuid
from django.db import models
from ..institution.model import Institution
from ..location.model import Location
class Cafeteria(models.Model):
cafeteria_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=50, blank=False, null=False)
location = models.OneToOneField(Location, on_delete=models.DO_NOTHING)
website = models.URLField()
institutes = models.ManyToManyField(Institution)
def __str__(self):
return '{} ({})'.format(self.name, self.location)

View file

View file

@ -0,0 +1,22 @@
import uuid
from django.db import models
from api_v1.location.model import Location
class Institution(models.Model):
institution_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=150, blank=False, null=False)
description = models.TextField(null=True)
location = models.OneToOneField(Location, on_delete=models.DO_NOTHING, null=True, blank=True)
website = models.URLField(null=True)
def __str__(self):
result = self.name
if self.description:
result += f' - {self.description}'
return result

View file

22
api_v1/location/model.py Normal file
View file

@ -0,0 +1,22 @@
import uuid
from django.db import models
class Location(models.Model):
location_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
longitude = models.DecimalField(max_digits=9, decimal_places=6)
latitude = models.DecimalField(max_digits=9, decimal_places=6)
country_code = models.CharField(max_length=2) # Following ISO-3166-1
country_name = models.CharField(max_length=50)
city = models.CharField(max_length=50)
postal_code = models.CharField(max_length=20)
street = models.CharField(max_length=50)
number = models.CharField(max_length=20)
def __str__(self):
return '{} {}, {} {}, {} {}'.format(self.street, self.number, self.postal_code, self.city, self.country_code,
self.country_name)

View file

@ -0,0 +1,28 @@
# Generated by Django 5.0.2 on 2024-02-28 20:03
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api_v1', '0002_rebrandUserInformationToProfile'),
]
operations = [
migrations.CreateModel(
name='Location',
fields=[
('location_id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('longitude', models.DecimalField(decimal_places=6, max_digits=9)),
('latitude', models.DecimalField(decimal_places=6, max_digits=9)),
('country_code', models.CharField(max_length=2)),
('country_name', models.CharField(max_length=50)),
('city', models.CharField(max_length=50)),
('postal_code', models.CharField(max_length=20)),
('street', models.CharField(max_length=50)),
('number', models.CharField(max_length=20)),
],
),
]

View file

@ -0,0 +1,24 @@
# Generated by Django 5.0.2 on 2024-02-28 20:03
import django.db.models.deletion
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api_v1', '0003_createdLocationModel'),
]
operations = [
migrations.CreateModel(
name='Cafeteria',
fields=[
('cafeteria_id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=50)),
('website', models.URLField()),
('location', models.OneToOneField(on_delete=django.db.models.deletion.DO_NOTHING, to='api_v1.location')),
],
),
]

View file

@ -0,0 +1,30 @@
# Generated by Django 5.0.2 on 2024-02-28 20:23
import django.db.models.deletion
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api_v1', '0004_createdCafeteriaModel'),
]
operations = [
migrations.CreateModel(
name='Institution',
fields=[
('institution_id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
('name', models.CharField(max_length=150)),
('description', models.TextField(null=True)),
('website', models.URLField(null=True)),
('location', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='api_v1.location')),
],
),
migrations.AddField(
model_name='cafeteria',
name='institutes',
field=models.ManyToManyField(to='api_v1.institution'),
),
]

View file

@ -1 +1,4 @@
from api_v1.profile.profile import Profile
from api_v1.profile.model import Profile
from api_v1.location.model import Location
from api_v1.cafeteria.model import Cafeteria
from api_v1.institution.model import Institution

View file

@ -6,3 +6,6 @@ class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
display_name = models.CharField(max_length=150, null=False)
def __str__(self):
return '{} ({})'.format(self.display_name, self.user)

View file

@ -1,4 +1,4 @@
from api_v1.profile.profile import Profile
from api_v1.profile.model import Profile
from django.contrib.auth.models import User
from typing import Optional