Skip to content

Commit

Permalink
Updates people_db serializers to make options requests not blow up.
Browse files Browse the repository at this point in the history
This is another fix for encode/django-rest-framework#3751, which is an upstream issue that causes the OPTIONS requests to list out every possible FK for an item as possible choices. That's fine and all, except when you have thousands or millions of FKs on an item, as we pretty much always do.
  • Loading branch information
mlissner committed Mar 22, 2016
1 parent 7f36c9e commit 6721d8d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 7 deletions.
1 change: 0 additions & 1 deletion cl/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@


urlpatterns = [
# url(r'^api/rest/(?P<version>[v3]+)/', include(router.urls)),
url(r'^api-auth/',
include('rest_framework.urls', namespace='rest_framework')),
url(r'^api/rest/(?P<version>[v3]+)/', include(router.urls)),
Expand Down
61 changes: 55 additions & 6 deletions cl/people_db/api_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,117 @@
from cl.api.utils import DynamicFieldsModelSerializer
from cl.people_db.models import Person, Position, RetentionEvent, \
Education, School, PoliticalAffiliation, Source, ABARating
from cl.search.api_serializers import CourtSerializer


class SchoolSerializer(DynamicFieldsModelSerializer,
serializers.HyperlinkedModelSerializer):
is_alias_of = serializers.HyperlinkedRelatedField(
many=False,
view_name='school-detail',
read_only=True
)

class Meta:
model = School


class EducationSerializer(DynamicFieldsModelSerializer,
serializers.HyperlinkedModelSerializer):
school = SchoolSerializer(many=False, read_only=True)
person = serializers.HyperlinkedRelatedField(
many=False,
view_name='person-detail',
read_only=True,
)

class Meta:
model = Education


class PoliticalAffiliationSerializer(DynamicFieldsModelSerializer,
serializers.HyperlinkedModelSerializer):
person = serializers.HyperlinkedRelatedField(
many=False,
view_name='person-detail',
read_only=True,
)

class Meta:
model = PoliticalAffiliation


class SourceSerializer(DynamicFieldsModelSerializer,
serializers.HyperlinkedModelSerializer):
person = serializers.HyperlinkedRelatedField(
many=False,
view_name='person-detail',
read_only=True,
)

class Meta:
model = Source


class ABARatingSerializer(DynamicFieldsModelSerializer,
serializers.HyperlinkedModelSerializer):
person = serializers.HyperlinkedRelatedField(
many=False,
view_name='person-detail',
read_only=True,
)

class Meta:
model = ABARating


class PersonSerializer(DynamicFieldsModelSerializer,
serializers.HyperlinkedModelSerializer):
race = serializers.StringRelatedField(many=True)
sources = SourceSerializer(many=True, read_only=True)
aba_ratings = ABARatingSerializer(many=True, read_only=True)
educations = EducationSerializer(many=True, read_only=True)
positions = serializers.HyperlinkedRelatedField(
many=True,
view_name='position-detail',
read_only=True,
)
educations = EducationSerializer(many=True, read_only=True)
political_affiliations = PoliticalAffiliationSerializer(many=True,
read_only=True)
sources = SourceSerializer(many=True, read_only=True)
aba_ratings = ABARatingSerializer(many=True, read_only=True)
political_affiliations = PoliticalAffiliationSerializer(
many=True,
read_only=True
)
is_alias_of = serializers.HyperlinkedRelatedField(
many=False,
view_name='person-detail',
read_only=True
)

class Meta:
model = Person


class RetentionEventSerializer(DynamicFieldsModelSerializer,
serializers.HyperlinkedModelSerializer):
position = serializers.HyperlinkedRelatedField(
many=False,
view_name='position-detail',
read_only=True,
)

class Meta:
model = RetentionEvent


class PositionSerializer(DynamicFieldsModelSerializer,
serializers.HyperlinkedModelSerializer):
appointer = PersonSerializer(many=False, read_only=True)
retention_events = RetentionEventSerializer(many=True, read_only=True)
person = PersonSerializer(many=False, read_only=True)
appointer = PersonSerializer(many=False, read_only=True)
supervisor = PersonSerializer(many=False, read_only=True)
predecessor = PersonSerializer(many=False, read_only=True)
school = SchoolSerializer(many=False, read_only=True)
court = CourtSerializer(many=False, read_only=True)

# TODO: add clerks

class Meta:
Expand Down

0 comments on commit 6721d8d

Please sign in to comment.