aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/serializers.py
diff options
context:
space:
mode:
authorCarl Meyer2014-10-16 12:16:13 -0600
committerCarl Meyer2014-10-17 09:50:57 -0600
commit140f8620aea44daa368b244d96c68377716fac7e (patch)
treea9be3c9063dcf9e2d9705ce652b7183eac523178 /rest_framework/serializers.py
parent34a7a48c1d0ee72f93aa9ff646192269a0451fd5 (diff)
downloaddjango-rest-framework-140f8620aea44daa368b244d96c68377716fac7e.tar.bz2
Set up serializer fields lazily on-demand.
This avoids AppRegistryNotReady problems in Django 1.7 with nested serializers, which are instantiated at import time, possibly before Django's app registry is fully populated.
Diffstat (limited to 'rest_framework/serializers.py')
-rw-r--r--rest_framework/serializers.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py
index b3db3582..340c6be0 100644
--- a/rest_framework/serializers.py
+++ b/rest_framework/serializers.py
@@ -22,6 +22,7 @@ from django.db import models
from django.forms import widgets
from django.utils import six
from django.utils.datastructures import SortedDict
+from django.utils.functional import cached_property
from django.core.exceptions import ObjectDoesNotExist
from rest_framework.settings import api_settings
@@ -197,7 +198,6 @@ class BaseSerializer(WritableField):
self.init_data = data
self.init_files = files
self.object = instance
- self.fields = self.get_fields()
self._data = None
self._files = None
@@ -212,6 +212,10 @@ class BaseSerializer(WritableField):
#####
# Methods to determine which fields to use when (de)serializing objects.
+ @cached_property
+ def fields(self):
+ return self.get_fields()
+
def get_default_fields(self):
"""
Return the complete set of default fields for the object, as a dict.