Commit 97c6be13 authored by Florent Chehab's avatar Florent Chehab

UniversityInfo model added, Currency model moved

parent 63622d41
Pipeline #26327 passed with stages
in 1 minute and 23 seconds
......@@ -2,6 +2,7 @@ from django.contrib import admin
from reversion_compare.admin import CompareVersionAdmin
from rex.models.university import University, Campus, UniversityScholarship
from rex.models.university import UniversityInfo
from rex.models.location import Country, City
......@@ -11,3 +12,4 @@ admin.site.register(City)
admin.site.register(University, CompareVersionAdmin)
admin.site.register(Campus, CompareVersionAdmin)
admin.site.register(UniversityScholarship, CompareVersionAdmin)
admin.site.register(UniversityInfo, CompareVersionAdmin)
# Generated by Django 2.0.3 on 2018-08-20 15:48
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import rex.models.tools.usefullLinksField
class Migration(migrations.Migration):
dependencies = [
('rex', '0006_auto_20180820_1715'),
]
operations = [
migrations.CreateModel(
name='UniversityInfo',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('comment', models.TextField(blank=True)),
('usefull_links', rex.models.tools.usefullLinksField.UsefullLinksField(blank=True, default=[], validators=[rex.models.tools.usefullLinksField.validate_usefull_links])),
('cost_exchange', models.DecimalField(decimal_places=2, max_digits=20, null=True, validators=[django.core.validators.MinValueValidator(0)])),
('cost_double_degree', models.DecimalField(decimal_places=2, max_digits=20, null=True, validators=[django.core.validators.MinValueValidator(0)])),
('costs_currency', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='rex.Currency')),
('university', models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='university_info', to='rex.University')),
],
options={
'abstract': False,
},
),
]
# Generated by Django 2.0.3 on 2018-08-20 15:52
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('rex', '0007_universityinfo'),
]
operations = [
migrations.RemoveField(
model_name='universityinfo',
name='id',
),
migrations.AlterField(
model_name='universityinfo',
name='university',
field=models.OneToOneField(default=1, on_delete=django.db.models.deletion.CASCADE, primary_key=True, related_name='university_info', serialize=False, to='rex.University'),
preserve_default=False,
),
]
from .module import Module # noqa: F401
from .basicModule import BasicModule # noqa: F401
from .scholarship import Scholarship # noqa: F401
from .currency import Currency, CurrencyViewSet, CurrencySerializer # noqa: F401
......@@ -3,7 +3,7 @@ from reversion.models import Version
class Module(models.Model):
def modified_date(self):
try:
v = Version.objects.get_for_object(self)
......
from django.db import models
from rex.models.module import BasicModule
from rex.models.module.currency import Currency
from rex.models.tools import Currency
from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator
......
from .DictModeViewSet import DictModeViewSet # noqa: F401
from .usefullLinksField import UsefullLinksField # noqa: F401
from .validateWithRestFramework import validate_with_rest_framework # noqa: F401
from .currency import Currency, CurrencyViewSet, CurrencySerializer # noqa: F401
......@@ -2,3 +2,4 @@ from .university import University # noqa: F401
from .campus import Campus, CampusViewSet, CampusSerializer # noqa: F401
from .universityAPI import UniversitySerializer, UniversityViewSet # noqa: F401
from .universityScholarship import UniversityScholarship, UniversityScholarshipViewSet # noqa: F401
from .universityInfo import UniversityInfo, UniversityInfoViewSet # noqa: F401
from django.db import models
from rex.models.module import BasicModule
from rex.models.university import University
from rex.models.tools import Currency
from django.core.validators import MinValueValidator
from rest_framework import serializers, viewsets, permissions
class UniversityInfo(BasicModule):
university = models.OneToOneField(
University, on_delete=models.CASCADE, related_name='university_info', primary_key=True, null=False)
cost_exchange = models.DecimalField(
decimal_places=2,
max_digits=20,
validators=[MinValueValidator(0)],
null=True
)
cost_double_degree = models.DecimalField(
decimal_places=2,
max_digits=20,
validators=[MinValueValidator(0)],
null=True
)
costs_currency = models.ForeignKey(Currency, on_delete=models.PROTECT)
class UniversityInfoSerializer(serializers.ModelSerializer):
# TODO generalize below
modified_by = serializers.SerializerMethodField()
modified_date = serializers.SerializerMethodField()
def get_modified_by(self, obj):
return obj.modified_by()
def get_modified_date(self, obj):
return obj.modified_date()
class Meta:
model = UniversityInfo
fields = ('university', 'cost_exchange', 'cost_double_degree',
'costs_currency', 'modified_by', 'modified_date')
class UniversityInfoViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
queryset = UniversityInfo.objects.all() # pylint: disable=E1101
serializer_class = UniversityInfoSerializer
from django.conf.urls import url, include
from rex import views
from rest_framework import routers
from rex.models.location import CountryViewSet, CityViewSet
from rex.models.university import CampusViewSet, UniversityViewSet, UniversityScholarshipViewSet
from rex.models.module import CurrencyViewSet
from rex.models.location import CountryViewSet
from rex.models.location import CityViewSet
from rex.models.university import UniversityViewSet
from rex.models.university import CampusViewSet
from rex.models.university import UniversityScholarshipViewSet
from rex.models.university import UniversityInfoViewSet
from rex.models.tools import CurrencyViewSet
from rest_framework.documentation import include_docs_urls
......@@ -19,6 +23,7 @@ router.register(r'city', CityViewSet)
router.register(r'campus', CampusViewSet)
router.register(r'university', UniversityViewSet)
router.register(r'university_scholarship', UniversityScholarshipViewSet)
router.register(r'university_info', UniversityInfoViewSet)
router.register(r'currency', CurrencyViewSet)
urlpatterns += [url(r'^api/', include(router.urls))]
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