aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/validators.py
diff options
context:
space:
mode:
authorTom Christie2011-05-04 09:21:17 +0100
committerTom Christie2011-05-04 09:21:17 +0100
commitd373b3a067796b8e181be9368fa24e89c572c45e (patch)
treeeec24eb8f8813ce959511c3572a54c5ee645e227 /djangorestframework/validators.py
parent8756664e064a18afc4713d921c318cd968f18433 (diff)
downloaddjango-rest-framework-d373b3a067796b8e181be9368fa24e89c572c45e.tar.bz2
Decouple views and resources
Diffstat (limited to 'djangorestframework/validators.py')
-rw-r--r--djangorestframework/validators.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/djangorestframework/validators.py b/djangorestframework/validators.py
index c612de55..d806a614 100644
--- a/djangorestframework/validators.py
+++ b/djangorestframework/validators.py
@@ -159,7 +159,7 @@ class ModelFormValidator(FormValidator):
otherwise if model is set use that class to create a ModelForm, otherwise return None."""
form_cls = getattr(self.view, 'form', None)
- model_cls = getattr(self.view, 'model', None)
+ model_cls = getattr(self.view.resource, 'model', None)
if form_cls:
# Use explict Form
@@ -189,9 +189,10 @@ class ModelFormValidator(FormValidator):
@property
def _model_fields_set(self):
"""Return a set containing the names of validated fields on the model."""
- model = getattr(self.view, 'model', None)
- fields = getattr(self.view, 'fields', self.fields)
- exclude_fields = getattr(self.view, 'exclude_fields', self.exclude_fields)
+ resource = self.view.resource
+ model = getattr(resource, 'model', None)
+ fields = getattr(resource, 'fields', self.fields)
+ exclude_fields = getattr(resource, 'exclude_fields', self.exclude_fields)
model_fields = set(field.name for field in model._meta.fields)
@@ -203,9 +204,10 @@ class ModelFormValidator(FormValidator):
@property
def _property_fields_set(self):
"""Returns a set containing the names of validated properties on the model."""
- model = getattr(self.view, 'model', None)
- fields = getattr(self.view, 'fields', self.fields)
- exclude_fields = getattr(self.view, 'exclude_fields', self.exclude_fields)
+ resource = self.view.resource
+ model = getattr(resource, 'model', None)
+ fields = getattr(resource, 'fields', self.fields)
+ exclude_fields = getattr(resource, 'exclude_fields', self.exclude_fields)
property_fields = set(attr for attr in dir(model) if
isinstance(getattr(model, attr, None), property)