Hi guys,
I wonder why my query to view the list of scholarships takes quite long to
load even though the number of rows is small. Would be great if someone
could help me out here.
Thanks.
Here's my view.
> class DualSerializerViewSet(viewsets.ReadOnlyModelViewSet):
> queryset = Scholarship.objects.all()
> filter_class = ScholarshipFilter
> """ViewSet providing different serializer for list and details view"""
> def get_serializer_class(self):
> if self.action == 'list':
> return ListScholarshipSerializer
> if self.action == 'retrieve':
> return DetailScholarshipSerializer
Here's my serializers.
> class ListScholarshipSerializer(serializers.ModelSerializer):
> """Serializer when showing scholarship list"""
> offer_levels =
> ScholarshipOfferLevelSerializer(source='scholarshipofferlevel_set',
> many=True)
> offer_courses =
> ScholarshipOfferCourseSerializer(source='scholarshipoffercourse_set',
> many=True)
> # institutions =
> ScholarshipOfferInstitutionSerializer(source='scholarshipofferinstitution_set',
>
> many=True)
> offer_countries =
> ScholarshipOfferCountrySerializer(source='scholarshipoffercountry_set',
> many=True)
> class Meta:
> model = Scholarship
> fields = ('scholarship_id', 'title', 'info_url', 'opening_date',
> 'closing_date',
> 'offer_levels', 'offer_courses', 'offer_countries')
> # serializer to use when showing scholarship details
> class DetailScholarshipSerializer(serializers.ModelSerializer):
> """Serializer when showing scholarship details"""
> tuition_benefit = TuitionBenefitSerializer()
> offer_levels =
> ScholarshipOfferLevelSerializer(source='scholarshipofferlevel_set',
> many=True)
> offer_courses =
> ScholarshipOfferCourseSerializer(source='scholarshipoffercourse_set',
> many=True)
> other_benefits =
> ScholarshipOfferBenefitSerializer(source='scholarshipofferbenefit_set',
> many=True)
> institutions =
> ScholarshipOfferInstitutionSerializer(source='scholarshipofferinstitution_set',
>
> many=True)
> offer_countries =
> ScholarshipOfferCountrySerializer(source='scholarshipoffercountry_set',
> many=True)
> status_eligibility =
> ScholarshipStatusEligibilitySerializer(source='statuseligibility_set',
> many=True)
> academic_eligibility =
> ScholarshipAcademicEligibilitySerializer(source='academiceligibility_set',
> many=True)
> apply_guide = ApplicationGuideSerializer()
> class Meta:
> model = Scholarship
And this is the scholarship model.
> class Scholarship(models.Model):
> NATIONALITY = (
> ('Malaysian','Malaysian'),
> ('Any','Any'),
> )
> scholarship_id = models.AutoField(primary_key=True)
> title = models.CharField(max_length=100, unique=True)
> opening_date = models.DateField(null=True)
> closing_date = models.DateField(null=True)
> info_url = models.URLField(max_length=2048, null=True)
> description = models.TextField(null=True)
> contact_email = models.EmailField(null=True)
> contact_number = models.CharField(max_length=150, null=True)
> bond = models.NullBooleanField()
> bond_length = models.CharField(max_length=100, null=True)
> eligible_age = IntegerRangeField(null = True)
> eligible_income = models.DecimalField(max_digits=10, decimal_places=2,
> blank=True, default=0, null=True)
> other_eligibility = models.TextField(null=True)
> tuition_benefit = models.ForeignKey(TuitionBenefit,
> related_name='scholarship')
> apply_guide = models.OneToOneField(ApplicationGuide, null=True)
> academic_eligibility = models.ManyToManyField(Academic,
> through='AcademicEligibility')
> status_eligibility = models.ManyToManyField(Status,
> through='StatusEligibility')
> offer_levels = models.ManyToManyField(StudyLevel, through =
> 'ScholarshipOfferLevel')
> offer_courses = models.ManyToManyField(Course, through =
> 'ScholarshipOfferCourse')
> other_benefits = models.ManyToManyField(OtherBenefit, through=
> 'ScholarshipOfferBenefit')
> institutions = models.ManyToManyField(Institution, through=
> 'ScholarshipOfferInstitution')
> offer_countries = models.ManyToManyField(Country, through=
> 'ScholarshipOfferCountry')
> class Meta:
> db_table = 'scholarship_general_info'
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/cfa1bb9b-9deb-4bcc-8036-03235ed98380%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.