Browse Source

inclui em drfautoapi a construção individual para models

pull/3606/head
LeandroJatai 3 years ago
parent
commit
a44af3c667
  1. 21
      drfautoapi/drfautoapi.py

21
drfautoapi/drfautoapi.py

@ -3,8 +3,11 @@ import importlib
import inspect import inspect
import logging import logging
from django.apps.config import AppConfig
from django.apps.registry import apps
from django.conf import settings from django.conf import settings
from django.contrib.postgres.fields.jsonb import JSONField from django.contrib.postgres.fields.jsonb import JSONField
from django.db.models.base import ModelBase
from django.db.models.fields.files import FileField from django.db.models.fields.files import FileField
from django.template.defaultfilters import capfirst from django.template.defaultfilters import capfirst
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -169,7 +172,7 @@ class ApiViewSetConstrutor():
return router return router
@classmethod @classmethod
def build_class(cls, apps): def build_class(cls, apps_or_models):
DRFAUTOAPI = settings.DRFAUTOAPI DRFAUTOAPI = settings.DRFAUTOAPI
@ -272,8 +275,20 @@ class ApiViewSetConstrutor():
viewset.__name__ = '%sModelViewSet' % _model.__name__ viewset.__name__ = '%sModelViewSet' % _model.__name__
return viewset return viewset
for app in apps: for am in apps_or_models:
cls._built_sets[app] = {}
if isinstance(am, ModelBase):
app = am._meta.app_config
else:
app = am
if app not in cls._built_sets:
cls._built_sets[app] = {}
if am != app:
cls._built_sets[app][am] = build(am)
continue
for model in app.get_models(): for model in app.get_models():
cls._built_sets[app][model] = build(model) cls._built_sets[app][model] = build(model)

Loading…
Cancel
Save