3👍
✅
use attrs['Ficha_publicada']
:
if not attrs['Ficha_publicada']:
raise serializers.ValidationError("Ficha no publicada")
return attrs
5👍
And for Django rest framework 3.0
and more recent versions:
def validate_Titulo(self, value):
3👍
For Django 1.8 you need to use a slightly different method signature.
From (<1.8)
def validate_Titulo(self, attrs, source):
To (1.8)
def validate_Titulo(self, attrs, source=None):
If you do not add the default None
to the source
argument in Django 1.8 you will get a TypeError exception saying:
validate_Titulo() missing 1 required positional argument: ‘source’
- [Django]-Python catch previous exception in broad handler
- [Django]-Limiting results returned fromquery in django, python
- [Django]-Does Neomodel support modelform? If so, why isn't it picking up default meta attributes / how do I set them?
Source:stackexchange.com