from tastypie import fields
from tastypie.resources import ModelResource
from core.models import Term, Subject, Course, Section, Grade

class TermResource(ModelResource):
    class Meta:
        queryset = Term.objects.all()
        allowed_methods = ['get']

class SubjectResource(ModelResource):
    class Meta:
        queryset = Subject.objects.all()
        allowed_methods = ['get']

class CourseResource(ModelResource):
    subject = fields.ForeignKey(SubjectResource, 'subject')

    class Meta:
        queryset = Course.objects.all()
        allowed_methods = ['get']

class SectionResource(ModelResource):
    course = fields.ForeignKey(CourseResource, 'course')
    term = fields.ForeignKey(TermResource, 'term')
    grade_average = fields.FloatField(readonly=True)

    class Meta:
        queryset = Section.objects.all()
        allowed_methods = ['get']

    def dehydrate_grade_average(self, bundle):
        return bundle.obj.grade_average

class GradeResource(ModelResource):
    class Meta:
        queryset = Grade.objects.all()
        allowed_methods = ['get']

@@ -65,17 +65,42 @@
 Resource
+, ALL, ALL_WITH_RELATIONS
 %0A
-
 from cor
@@ -268,32 +268,138 @@
 ethods = %5B'get'%5D
+%0A        fitering = %7B%0A            'season': ALL,%0A            'year': ALL,%0A            'id': ALL,%0A        %7D
 %0A%0Aclass SubjectR
@@ -504,32 +504,112 @@
 ethods = %5B'get'%5D
+%0A        filtering = %7B%0A            'name': ALL,%0A            'id': ALL,%0A        %7D
 %0A%0Aclass CourseRe
@@ -781,16 +781,141 @@
  %5B'get'%5D
+%0A        filtering = %7B%0A            'subject': ALL_WITH_RELATIONS,%0A            'number': ALL,%0A            'id': ALL,%0A        %7D
 %0A%0Aclass 
@@ -1198,16 +1198,177 @@
  %5B'get'%5D
+%0A        filtering = %7B%0A            'course': ALL_WITH_RELATIONS,%0A            'term': ALL_WITH_RELATIONS,%0A            'ccn': ALL,%0A            'id': ALL,%0A        %7D
 %0A%0A    de
@@ -1532,32 +1532,32 @@
 e.objects.all()%0A
-
         allowed_
@@ -1554,28 +1554,83 @@
   allowed_methods = %5B'get'%5D%0A
+        filtering = %7B%0A            'id': ALL,%0A        %7D%0A

add filtering to API