Commit f3cbb6c7 authored by Florent Chehab's avatar Florent Chehab

Model get_serializer added everywhere

parent 73f73809
Pipeline #26661 passed with stages
in 3 minutes
......@@ -18,7 +18,9 @@ from backend.models.location import CityTransport
from backend.models.location import CityTourism
from backend.models.location import CityOtherStuff
from backend.models.university import University, Campus, UniversityScholarship
from backend.models.university import University
from backend.models.university import Campus
from backend.models.university import UniversityScholarship
from backend.models.university import UniversityInfo
from backend.models.university import UniversitySemestersDates
......@@ -102,3 +104,6 @@ for model in CLASSIC_MODELS:
for model in VERSIONNED_MODELS:
admin.site.register(model, CompareVersionAdmin)
if (model.get_serializer().Meta.model != model):
raise Exception(
"Get_serializer configuration incorrect in", str(model))
......@@ -11,7 +11,8 @@ class CityTransport(BasicModule):
city = models.OneToOneField(
City, on_delete=models.CASCADE, related_name='city_transport', primary_key=True)
def get_serializer(self):
@classmethod
def get_serializer(cls):
return CityTransportSerializer
......@@ -39,6 +40,10 @@ class CityTourism(BasicModule):
city = models.OneToOneField(
City, on_delete=models.CASCADE, related_name='city_tourism', primary_key=True)
@classmethod
def get_serializer(cls):
return CityTourismSerializer
class CityTourismSerializer(BasicModuleSerializer):
class Meta:
......@@ -64,6 +69,10 @@ class CityOtherStuff(BasicModule):
city = models.OneToOneField(
City, on_delete=models.CASCADE, related_name='city_other_stuff', primary_key=True)
@classmethod
def get_serializer(cls):
return CityOtherStuffSerializer
class CityOtherStuffSerializer(BasicModuleSerializer):
class Meta:
......
......@@ -10,6 +10,10 @@ class CityPhoto(Photo):
on_delete=models.CASCADE,
related_name='city_photos')
@classmethod
def get_serializer(cls):
return CityPhotoSerializer
class Meta:
unique_together = ('city', 'photo')
......
......@@ -11,6 +11,10 @@ class CountryVisaAdministrative(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_visa_administrative', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryVisaAdministrativeSerializer
class CountryVisaAdministrativeSerializer(BasicModuleSerializer):
class Meta:
......@@ -37,6 +41,10 @@ class CountryHealthInsurance(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_health_insurances', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryHealthInsuranceSerializer
class CountryHealthInsuranceSerializer(BasicModuleSerializer):
class Meta:
......@@ -62,6 +70,10 @@ class CountryOtherInsurance(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_other_insurances', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryOtherInsuranceSerializer
class CountryOtherInsuranceSerializer(BasicModuleSerializer):
class Meta:
......@@ -86,6 +98,10 @@ class CountryCulture(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_culture', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryCultureSerializer
class CountryCultureSerializer(BasicModuleSerializer):
class Meta:
......@@ -110,6 +126,10 @@ class CountryTransport(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_transport', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryTransportSerializer
class CountryTransportSerializer(BasicModuleSerializer):
class Meta:
......@@ -135,6 +155,10 @@ class CountryTourism(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_tourism', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryTourismSerializer
class CountryTourismSerializer(BasicModuleSerializer):
class Meta:
......@@ -160,6 +184,10 @@ class CountryOtherStuff(BasicModule):
country = models.OneToOneField(
Country, on_delete=models.CASCADE, related_name='country_other_stuff', primary_key=True)
@classmethod
def get_serializer(cls):
return CountryOtherStuffSerializer
class CountryOtherStuffSerializer(BasicModuleSerializer):
class Meta:
......
......@@ -7,6 +7,10 @@ class CountryDri(DriRestrictedModule):
country = models.ManyToManyField(
Country, related_name="country_dri")
@classmethod
def get_serializer(cls):
return CountryDriSerializer
class CountryDriSerializer(DriRestrictedModuleSerializer):
......
......@@ -10,6 +10,10 @@ class CountryPhoto(Photo):
on_delete=models.CASCADE,
related_name='country_photos')
@classmethod
def get_serializer(cls):
return CountryPhotoSerializer
class Meta:
unique_together = ('country', 'photo')
......
......@@ -7,6 +7,10 @@ class CountryScholarship(Scholarship):
country = models.ManyToManyField(
Country, related_name="country_scholarhip")
@classmethod
def get_serializer(cls):
return CountryScholarshipSerializer
class CountryScholarshipSerializer(ScholarshipSerializer):
......
......@@ -10,7 +10,8 @@ class ForTestingVersionning(MyModelVersionned):
"""
bbb = models.CharField(max_length=100)
def get_serializer(self):
@classmethod
def get_serializer(cls):
return ForTestingVersionningSerializer
......
......@@ -10,13 +10,14 @@ from django.core import serializers as djangoSerializers
class MyModelVersionned(MyModel):
def get_serializer(self):
@classmethod
def get_serializer(cls):
"""
This function is required for handling
versionning easily.
You have to put the correct value in each subclass
"""
return None
raise Exception("Get_serializer must be redifined in subclass")
class Meta:
abstract = True
......
......@@ -31,6 +31,10 @@ class Campus(BasicModule):
def location(self):
return {'lat': self.lat, 'lon': self.lon}
@classmethod
def get_serializer(cls):
return CampusSerializer
class Meta:
unique_together = ('is_main_campus', 'university')
......
......@@ -11,6 +11,10 @@ class CampusCultureAndStudentLife(BasicModule):
campus = models.OneToOneField(
Campus, on_delete=models.CASCADE, related_name='campus_culture_and_sl', primary_key=True)
@classmethod
def get_serializer(cls):
return CampusCultureAndStudentLifeSerializer
class CampusCultureAndStudentLifeSerializer(BasicModuleSerializer):
class Meta:
......@@ -34,6 +38,10 @@ class CampusAccommodation(BasicModule):
campus = models.OneToOneField(
Campus, on_delete=models.CASCADE, related_name='campus_accomodation', primary_key=True)
@classmethod
def get_serializer(cls):
return CampusAccommodationSerializer
class CampusAccommodationSerializer(BasicModuleSerializer):
class Meta:
......@@ -57,6 +65,10 @@ class CampusTransport(BasicModule):
campus = models.OneToOneField(
Campus, on_delete=models.CASCADE, related_name='campus_transport', primary_key=True)
@classmethod
def get_serializer(cls):
return CampusTransportSerializer
class CampusTransportSerializer(BasicModuleSerializer):
class Meta:
......@@ -81,6 +93,10 @@ class CampusOtherStuff(BasicModule):
campus = models.OneToOneField(
Campus, on_delete=models.CASCADE, related_name='campus_other_stuff', primary_key=True)
@classmethod
def get_serializer(cls):
return CampusOtherStuffSerializer
class CampusOtherStuffSerializer(BasicModuleSerializer):
class Meta:
......
......@@ -12,6 +12,10 @@ class UniversityInsurance(BasicModule):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_insurances', primary_key=True)
@classmethod
def get_serializer(cls):
return UniversityInsuranceSerializer
class UniversityInsuranceSerializer(BasicModuleSerializer):
class Meta:
......@@ -35,6 +39,10 @@ class UniversityCulture(BasicModule):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_culture', primary_key=True)
@classmethod
def get_serializer(cls):
return UniversityCultureSerializer
class UniversityCultureSerializer(BasicModuleSerializer):
class Meta:
......@@ -58,6 +66,10 @@ class UniversityCourses(BasicModule):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_courses', primary_key=True)
@classmethod
def get_serializer(cls):
return UniversityCoursesSerializer
class UniversityCoursesSerializer(BasicModuleSerializer):
class Meta:
......@@ -83,6 +95,10 @@ class UniversitySpecialOffer(BasicModule):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_special_offer', primary_key=True)
@classmethod
def get_serializer(cls):
return UniversitySpecialOfferSerializer
class UniversitySpecialOfferSerializer(BasicModuleSerializer):
class Meta:
......@@ -107,6 +123,10 @@ class UniversityOtherStuff(BasicModule):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_other_stuff', primary_key=True)
@classmethod
def get_serializer(cls):
return UniversityOtherStuffSerializer
class UniversityOtherStuffSerializer(BasicModuleSerializer):
class Meta:
......
......@@ -7,6 +7,10 @@ class UniversityDri(DriRestrictedModule):
university = models.ManyToManyField(
University, related_name="university_dri")
@classmethod
def get_serializer(cls):
return UniversityDriSerializer
class UniversityDriSerializer(DriRestrictedModuleSerializer):
......
......@@ -26,6 +26,10 @@ class UniversityInfo(BasicModule):
costs_currency = models.ForeignKey(Currency, on_delete=models.PROTECT)
@classmethod
def get_serializer(cls):
return UniversityInfoSerializer
class UniversityInfoSerializer(BasicModuleSerializer):
......
......@@ -10,6 +10,10 @@ class UniversityPhoto(Photo):
on_delete=models.CASCADE,
related_name='university_photos')
@classmethod
def get_serializer(cls):
return UniversityPhotoSerializer
class Meta:
unique_together = ('university', 'photo')
......
......@@ -7,6 +7,10 @@ class UniversityScholarship(Scholarship):
university = models.ForeignKey(
University, on_delete=models.PROTECT, null=False, related_name="univScholarship")
@classmethod
def get_serializer(cls):
return UniversityScholarshipSerializer
class UniversityScholarshipSerializer(ScholarshipSerializer):
......
......@@ -24,6 +24,9 @@ class UniversitySemestersDates(BasicModule):
autumn_begin = models.DateField(null=True, blank=True)
autumn_end = models.DateField(null=True, blank=True)
@classmethod
def get_serializer(cls):
return UniversitySemestersDatesSerializer
# Need custom validation
# TODO add tests
......
Markdown is supported
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