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
from backend.models.campus import CampusSerializer
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.utils import get_viewset_permissions
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_info = UniversityInfoSerializer(read_only=True)
university_semesters_dates = UniversitySemestersDatesSerializer(
read_only=True)
class Meta:
model = University
......@@ -18,9 +30,15 @@ class UniversityModulesSerializer(MyModelSerializer):
class UniversityModulesViewSet(MyModelViewSet):
permission_classes = get_viewset_permissions("UniversityModulesViewSet")
serializer_class = UniversityModulesSerializer
queryset = University.objects.all()
def get_queryset(self):
def extend_queryset(self):
univ_id = self.kwargs['univ_id']
return University.objects.filter(id=univ_id).prefetch_related('univ_campus', 'university_dri') # pylint: disable=E1101
# queryset = get_queryset()
return self.my_model_queryset.filter(pk=univ_id).prefetch_related(
'university_campuses',
'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
class UniversityScholarship(Scholarship):
model_config = get_model_config("UniversityScholarship")
university = models.ForeignKey(
University, on_delete=models.PROTECT, null=False, related_name="univScholarship")
university = models.ManyToManyField(University, related_name="university_scholarships")
@classmethod
def get_serializer(cls):
......
......@@ -7,7 +7,7 @@ from backend.utils import get_model_config, get_viewset_permissions
class UniversityTaggedItem(TaggedItem):
model_config = get_model_config("UniversityTaggedItem")
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
def get_serializer(cls):
......
......@@ -177,10 +177,34 @@
- model: null
viewset: UniversityModulesViewSet
import_location: university
api_end_point: universitiesAll
api_end_point: universityAll
api_attr: (?P<univ_id>[0-9]+)
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
......
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