SOLVED!
I added a default class with a set_context method to grab the data from the
request and combined with a HiddenField and the CreateOnlyDefault to limit
it to POST only
class LatLongDefault(object):
"""
Provide default ``lat_long`` field for validation on POST.
"""
def set_context(self, serializer_field):
request = serializer_field.context['request']
LOGGER.debug('request data\n:%r', request.data)
self.latitude = float(request.data['latitude'])
self.longitude = float(request.data['longitude'])
def __call__(self):
return '%.3f %.3f' % (self.latitude, self.longitude)
def __repr__(self):
return unicode_to_repr('%s()' % self.__class__.__name__)
class WeatherSerializer(serializers.ModelSerializer):
"""weather serializer"""
lat_long = serializers.HiddenField(
default=serializers.CreateOnlyDefault(LatLongDefault())
)
class Meta:
model = Weather
I copied the code from the CurrentUserDefault in GitHub.
Let me just say that DRF is really well written code, several times I have
gone back to the source and it's always been illuminating!
--
You received this message because you are subscribed to the Google Groups
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.