Найти - Пользователи
Полная версия: ленивая регистрация моделей в админке
Начало » Django » ленивая регистрация моделей в админке
1
chaotism
суть в том, что есть очень жирный файл с моделями сделаный inspectdb и хотелось, на этапе проверки работоспособности модели быстро зарегестрировать их в админку
хотелось не вбивать ручками имена моделей, а пройтись по ним циклом, но выпадаю в ошибку, что нужен объект класс, а дается строка.

from django.contrib import admin
from model import *
for name in dir(model):
      try:
          admin.site.register(name)
     except:
          pass




PanovSergey
from django.contrib import admin
from model import *
from types import ModuleType
for [mod for mod in locals()  if isinstance(mod, ModuleType) and mod.__module__ in ["model",] ]:
    admin.site.register(mod)    
chaotism
спасибо,затупил с globals() — Return a dictionary representing the current global symbol table.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB