-
-
Save jathanism/9320946 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tastypie.validation import FormValidation | |
class InstanceFormValidation(FormValidation): | |
def is_valid(self, bundle, request=None): | |
errors = {} | |
data = bundle.data | |
instance = bundle.obj | |
if data is None: | |
data = {} | |
form = self.form_class(data, instance=instance) | |
if not form.is_valid(): | |
errors.update(form.errors) | |
return errors | |
class InstanceCleanedDataFormValidation(FormValidation): | |
def is_valid(self, bundle, request=None): | |
errors = {} | |
data = bundle.data | |
instance = bundle.obj | |
if data is None: | |
data = {} | |
form = self.form_class(data, instance=instance) | |
if form.is_valid(): | |
bundle.data = form.cleaned_data | |
else: | |
errors.update(form.errors) | |
return errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment