Skip to content

Commit

Permalink
[bug-#119] Add support to "__all__" fields in serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Nov 23, 2016
1 parent 6c986b0 commit 654cc8b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions rest_framework_gis/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, *args, **kwargs):
default_id_field = None
primary_key = self.Meta.model._meta.pk.name
# use primary key as id_field when possible
if not hasattr(meta, 'fields') or primary_key in meta.fields:
if not hasattr(meta, 'fields') or meta.fields == '__all__' or primary_key in meta.fields:
default_id_field = primary_key
meta.id_field = getattr(meta, 'id_field', default_id_field)

Expand All @@ -67,7 +67,7 @@ def check_excludes(field_name, field_role):

def add_to_fields(field_name):
"""Make sure the field is included in the fields"""
if hasattr(meta, 'fields'):
if hasattr(meta, 'fields') and meta.fields != '__all__':
if field_name not in meta.fields:
if type(meta.fields) is tuple:
additional_fields = (field_name,)
Expand Down
6 changes: 3 additions & 3 deletions tests/django_restframework_gis_tests/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LocationGeoSerializer(serializers.ModelSerializer):

class Meta:
model = Location
exclude = []
fields = '__all__'


class PaginatedLocationGeoSerializer(pagination.PageNumberPagination):
Expand All @@ -47,7 +47,7 @@ def get_fancy_name(self, obj):
class Meta:
model = Location
geo_field = 'geometry'
exclude = []
fields = '__all__'


class LocationGeoFeatureSlugSerializer(LocationGeoFeatureSerializer):
Expand All @@ -65,7 +65,7 @@ class Meta:
model = Location
geo_field = 'geometry'
id_field = False
exclude = []
fields = '__all__'


class LocationGeoFeatureNoIdSerializer(LocationGeoFeatureSerializer):
Expand Down

0 comments on commit 654cc8b

Please sign in to comment.