예제 #1
0
from rest_framework import __version__
from rest_framework.routers import DefaultRouter

from tests.app.views import ExplosiveViewSet
from tests.app.views import QuoteViewSet
from tests.app.views import SnippetViewSet

v = tuple([int(x) for x in __version__.split(".")])
basename = 'basename' if v >= (3, 9) else 'base_name'

router = DefaultRouter()
router.register(r'quotes', QuoteViewSet, **{basename: 'api-quote'})
router.register(r'snippets', SnippetViewSet, **{basename: 'api-snippet'})
router.register(r'explosives', ExplosiveViewSet, **{basename: 'api-explosive'})
urlpatterns = router.urls
예제 #2
0
                                resettable_cached_property)
from dynamic_rest.conf import settings
from dynamic_rest.fields import (
    DynamicRelationField,
    DynamicGenericRelationField,
)
from dynamic_rest.links import merge_link_object
from dynamic_rest.meta import get_model_table
from dynamic_rest.processors import SideloadingProcessor, post_process
from dynamic_rest.tagged import tag_dict
from dynamic_rest.mixins import (NestedCreateMixin, NestedUpdateMixin,
                                 UniqueFieldsMixin)

OPTS = {'ENABLE_FIELDS_CACHE': os.environ.get('ENABLE_FIELDS_CACHE', False)}
FIELDS_CACHE = {}
DRF_VERSION = drf_version.split('.')


class WithResourceKeyMixin(object):
    def get_resource_key(self):
        """Return canonical resource key, usually the DB table name."""
        model = self.get_model()
        if model:
            return get_model_table(model)
        else:
            return self.get_name()


class DynamicListSerializer(CacheableFieldMixin, WithResourceKeyMixin,
                            serializers.ListSerializer):
    """Custom ListSerializer class.