Commit a49d5f70 authored by Florent Chehab's avatar Florent Chehab
Browse files

API to regroup info added and minor tweaks

parent b67fda5d
...@@ -2,13 +2,25 @@ from backend.models.university import University ...@@ -2,13 +2,25 @@ from backend.models.university import University
from backend.models.campus import CampusSerializer from backend.models.campus import CampusSerializer
from backend.models.university import UniversityDriSerializer from backend.models.university import UniversityDriSerializer
from backend.models.university import UniversityInfoSerializer
from backend.models.university import UniversityScholarshipSerializer
from backend.models.university import UniversitySemestersDatesSerializer
from backend.models.university import UniversityTaggedItemSerializer
from backend.models.abstract.my_model import MyModelSerializer, MyModelViewSet from backend.models.abstract.my_model import MyModelSerializer, MyModelViewSet
from backend.utils import get_viewset_permissions from backend.utils import get_viewset_permissions
class UniversityModulesSerializer(MyModelSerializer): class UniversityModulesSerializer(MyModelSerializer):
univ_campus = CampusSerializer(many=True, read_only=True) university_campuses = CampusSerializer(many=True, read_only=True)
university_scholarships = UniversityScholarshipSerializer(
many=True, read_only=True)
university_tagged_items = UniversityTaggedItemSerializer(
many=True, read_only=True)
university_dri = UniversityDriSerializer(many=True, read_only=True) university_dri = UniversityDriSerializer(many=True, read_only=True)
university_info = UniversityInfoSerializer(read_only=True)
university_semesters_dates = UniversitySemestersDatesSerializer(
read_only=True)
class Meta: class Meta:
model = University model = University
...@@ -18,9 +30,15 @@ class UniversityModulesSerializer(MyModelSerializer): ...@@ -18,9 +30,15 @@ class UniversityModulesSerializer(MyModelSerializer):
class UniversityModulesViewSet(MyModelViewSet): class UniversityModulesViewSet(MyModelViewSet):
permission_classes = get_viewset_permissions("UniversityModulesViewSet") permission_classes = get_viewset_permissions("UniversityModulesViewSet")
serializer_class = UniversityModulesSerializer serializer_class = UniversityModulesSerializer
queryset = University.objects.all()
def get_queryset(self): def extend_queryset(self):
univ_id = self.kwargs['univ_id'] univ_id = self.kwargs['univ_id']
return University.objects.filter(id=univ_id).prefetch_related('univ_campus', 'university_dri') # pylint: disable=E1101 return self.my_model_queryset.filter(pk=univ_id).prefetch_related(
'university_campuses',
# queryset = get_queryset() 'university_dri',
'university_info',
'university_scholarships',
'university_semesters_dates',
'university_tagged_items'
) # pylint: disable=E1101
...@@ -6,8 +6,7 @@ from backend.utils import get_model_config, get_viewset_permissions ...@@ -6,8 +6,7 @@ from backend.utils import get_model_config, get_viewset_permissions
class UniversityScholarship(Scholarship): class UniversityScholarship(Scholarship):
model_config = get_model_config("UniversityScholarship") model_config = get_model_config("UniversityScholarship")
university = models.ForeignKey( university = models.ManyToManyField(University, related_name="university_scholarships")
University, on_delete=models.PROTECT, null=False, related_name="univScholarship")
@classmethod @classmethod
def get_serializer(cls): def get_serializer(cls):
......
...@@ -7,7 +7,7 @@ from backend.utils import get_model_config, get_viewset_permissions ...@@ -7,7 +7,7 @@ from backend.utils import get_model_config, get_viewset_permissions
class UniversityTaggedItem(TaggedItem): class UniversityTaggedItem(TaggedItem):
model_config = get_model_config("UniversityTaggedItem") model_config = get_model_config("UniversityTaggedItem")
university = models.OneToOneField( university = models.OneToOneField(
University, on_delete=models.PROTECT, related_name='city_items', primary_key=True) University, on_delete=models.PROTECT, related_name='university_tagged_items', primary_key=True)
@classmethod @classmethod
def get_serializer(cls): def get_serializer(cls):
......
...@@ -177,10 +177,34 @@ ...@@ -177,10 +177,34 @@
- model: null - model: null
viewset: UniversityModulesViewSet viewset: UniversityModulesViewSet
import_location: university import_location: university
api_end_point: universitiesAll api_end_point: universityAll
api_attr: (?P<univ_id>[0-9]+) api_attr: (?P<univ_id>[0-9]+)
api_name: university_details api_name: university_details
read_only: true
- model: null
viewset: CountryModulesViewSet
import_location: country
api_end_point: countryAll
api_attr: (?P<country_id>[a-zA-Z]+)
api_name: country_details
read_only: true
- model: null
viewset: CityModulesViewSet
import_location: city
api_end_point: cityAll
api_attr: (?P<city_id>[0-9]+)
api_name: city_details
read_only: true
- model: null
viewset: CampusModulesViewSet
import_location: campus
api_end_point: campusAll
api_attr: (?P<campus_id>[0-9]+)
api_name: campus_details
read_only: true
- model: CampusTaggedItem - model: CampusTaggedItem
......
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