diff --git a/api_v1/admin.py b/api_v1/admin.py index 465ffc4..8718f5b 100644 --- a/api_v1/admin.py +++ b/api_v1/admin.py @@ -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) diff --git a/api_v1/cafeteria/__init__.py b/api_v1/cafeteria/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api_v1/cafeteria/model.py b/api_v1/cafeteria/model.py new file mode 100644 index 0000000..51f3029 --- /dev/null +++ b/api_v1/cafeteria/model.py @@ -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) diff --git a/api_v1/institution/__init__.py b/api_v1/institution/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api_v1/institution/model.py b/api_v1/institution/model.py new file mode 100644 index 0000000..06136e2 --- /dev/null +++ b/api_v1/institution/model.py @@ -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 diff --git a/api_v1/location/__init__.py b/api_v1/location/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api_v1/location/model.py b/api_v1/location/model.py new file mode 100644 index 0000000..f69b849 --- /dev/null +++ b/api_v1/location/model.py @@ -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) diff --git a/api_v1/migrations/0003_createdLocationModel.py b/api_v1/migrations/0003_createdLocationModel.py new file mode 100644 index 0000000..2b898fd --- /dev/null +++ b/api_v1/migrations/0003_createdLocationModel.py @@ -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)), + ], + ), + ] diff --git a/api_v1/migrations/0004_createdCafeteriaModel.py b/api_v1/migrations/0004_createdCafeteriaModel.py new file mode 100644 index 0000000..1d2dab1 --- /dev/null +++ b/api_v1/migrations/0004_createdCafeteriaModel.py @@ -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')), + ], + ), + ] diff --git a/api_v1/migrations/0005_addedInstitutionModel.py b/api_v1/migrations/0005_addedInstitutionModel.py new file mode 100644 index 0000000..87585cd --- /dev/null +++ b/api_v1/migrations/0005_addedInstitutionModel.py @@ -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'), + ), + ] diff --git a/api_v1/models.py b/api_v1/models.py index 69f6446..1cb81d8 100644 --- a/api_v1/models.py +++ b/api_v1/models.py @@ -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 diff --git a/api_v1/profile/profile.py b/api_v1/profile/model.py similarity index 74% rename from api_v1/profile/profile.py rename to api_v1/profile/model.py index 7229c28..3bb920d 100644 --- a/api_v1/profile/profile.py +++ b/api_v1/profile/model.py @@ -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) diff --git a/api_v1/profile/profile_services.py b/api_v1/profile/profile_services.py index c84b59b..3395f9d 100644 --- a/api_v1/profile/profile_services.py +++ b/api_v1/profile/profile_services.py @@ -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