Discussion:
Feature Suggestions: Use MySerializer.some_field to read validade_data
Ezequiel Bertti
2018-08-24 14:09:34 UTC
Permalink
Hi,

I want to suggest a feature on github, but first, I want to ask the group
about it.

Something like this:


class MySerializer(serializers.Serializer):
some_field = serializers.IntegerField()


def request(request):

serializer = MySerializer(data=request.GET)
if serializer.is_valid():
my_var = serializer.validated_data[MySerializer.some_field]
--
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 django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jason
2018-08-24 14:53:49 UTC
Permalink
my_var = serializer.validated_data[MySerializer.some_field]


in your example above, what exactly is MySerializer.some_field supposed to do? Is it a string for the field name, or is it the value of the field?


thing is, you can already do that with serializer.validated_data['field_name']


so what does this bring to the table?
--
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 django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ezequiel Bertti
2018-09-01 21:23:58 UTC
Permalink
Hi
Post by Ezequiel Bertti
my_var = serializer.validated_data[MySerializer.some_field]
in your example above, what exactly is MySerializer.some_field supposed to do? Is it a string for the field name, or is it the value of the field?
Value of field
Post by Ezequiel Bertti
thing is, you can already do that with serializer.validated_data['field_name']
so what does this bring to the table?
Will be easier to perform a refactor if necessary and check uses of some
field.

This is the same approach of DjangoChoices
[https://pypi.org/project/django-choices/]

This proposal does not invalidate the use of string, but could be a safer
use for code maintenance.
--
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 django-rest-framework+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...