You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently in our app we don't use Django Forms, all data goes through serializers and so basing from The solution provided here
Is it possible to declare the fields for a specific region validation?
i.e. something like:
class ASerializer(ModelSerializer):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
fields = getattr(self, "_fields", None)
try:
instance = args[0]
except IndexError:
instance = None
if not instance:
return
if not hasattr(instance, 'get_country', None):
return
country = instance.get_country
self._fields[field_name] = PhoneNumberField(region=country)
I am trying this approach but currently getting
File "xxx", line 274, in __init__
self._fields[field_name] = PhoneNumberField(region=country)
File "xxx/.pyenv/versions/3.6.11/envs/brokerengine/lib/python3.6/site-packages/rest_framework/fields.py", line 754, in __init__
super(CharField, self).__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'region'
Looks like custom regions in DRF serializers are not supported yet? (I may have to write additonal code for that)
By doing this will I be able to override the normal validation that happens for the default region?
The text was updated successfully, but these errors were encountered:
Hi
Currently in our app we don't use Django Forms, all data goes through serializers and so basing from
The solution provided here
Is it possible to declare the fields for a specific region validation?
i.e. something like:
I am trying this approach but currently getting
Looks like custom regions in DRF serializers are not supported yet? (I may have to write additonal code for that)
By doing this will I be able to override the normal validation that happens for the default region?
The text was updated successfully, but these errors were encountered: