Commit 19143adf authored by Gautier D's avatar Gautier D Committed by Gautier Daures
Browse files

refacto(backend): migrate university changes

parent 42a0d335
# Generated by Django 2.1.7 on 2020-04-17 12:30
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [("backend_app", "0001_initial")]
operations = [
migrations.AddField(
model_name="university",
name="city",
field=models.CharField(default="", max_length=200),
preserve_default=False,
),
migrations.AddField(
model_name="university",
name="country",
field=models.ForeignKey(
default="FR",
on_delete=django.db.models.deletion.PROTECT,
to="backend_app.Country",
),
preserve_default=False,
),
migrations.AddField(
model_name="university",
name="main_campus_lat",
field=models.DecimalField(
decimal_places=6,
default=0,
max_digits=10,
validators=[
django.core.validators.MinValueValidator(-85.05112878),
django.core.validators.MaxValueValidator(85.05112878),
],
),
preserve_default=False,
),
migrations.AddField(
model_name="university",
name="main_campus_lon",
field=models.DecimalField(
decimal_places=6,
default=0,
max_digits=10,
validators=[
django.core.validators.MinValueValidator(-180),
django.core.validators.MaxValueValidator(180),
],
),
preserve_default=False,
),
]
......@@ -40,6 +40,12 @@ class Campus(BaseModel):
class Meta:
unique_together = ("is_main_campus", "university")
def save(self, *args, **kwargs):
raise Exception("Can't edit model anymore")
def delete(self, *args, **kwargs):
raise Exception("Can't edit model anymore")
class CampusSerializer(BaseModelSerializer):
class Meta:
......
......@@ -17,6 +17,12 @@ class City(BaseModel):
area = models.CharField(max_length=200, default="", blank=True)
country = models.ForeignKey(Country, on_delete=models.PROTECT)
def save(self, *args, **kwargs):
raise Exception("Can't edit model anymore")
def delete(self, *args, **kwargs):
raise Exception("Can't edit model anymore")
class CitySerializer(BaseModelSerializer):
class Meta:
......
import logging
from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator
from backend_app.fields import JSONField
from backend_app.models.abstract.essentialModule import (
......@@ -10,6 +11,7 @@ from backend_app.models.abstract.essentialModule import (
)
from backend_app.models.file_picture import Picture
from backend_app.permissions.moderation import ModerationLevels
from backend_app.models.country import Country
logger = logging.getLogger("django")
......@@ -26,9 +28,27 @@ class University(EssentialModule):
logo = models.ForeignKey(Picture, null=True, on_delete=models.PROTECT)
website = models.URLField(default="", blank=True, max_length=300)
city = models.CharField(max_length=200)
country = models.ForeignKey(Country, on_delete=models.PROTECT)
main_campus_lat = models.DecimalField(
max_digits=10,
decimal_places=6,
validators=[MinValueValidator(-85.05112878), MaxValueValidator(85.05112878)],
)
main_campus_lon = models.DecimalField(
max_digits=10,
decimal_places=6,
validators=[MinValueValidator(-180), MaxValueValidator(180)],
)
# a bit of denormalization
denormalized_infos = JSONField(default=dict)
def location(self):
return {"lat": self.main_campus_lat, "lon": self.main_campus_lon}
class UniversitySerializer(EssentialModuleSerializer):
class Meta:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment