在不创建 table python 的情况下创建模型管理页面
Create model admin page without create table python
我是 Django 和 Python 的新手,我开始使用 Django CMS 使用此技术开发 CMS。
我需要创建一个模型管理页面来管理我的地块实体,但我的数据库中没有这个实体。基本上我会在索引列表中显示所有实体,像请求一样使用另一个服务。这是其他 CRUD 的想法。
当 create
、update
、delete
时,我将使用服务来对相应的实体进行此操作。为此,我将覆盖 admin.ModelAdmin
的 CRUD 方法。
有办法吗?
我到处找,但没有答案。
这是我已有的。
在我的admin.py
from django.contrib import admin
from cms.extensions import PageExtensionAdmin
from .models import LoteDestaque
from .models import LoteDestaqueTest
# from myproject.admin_site import custom_admin_site
@admin.register(LoteDestaqueTest)
这是我的 models.py
from .servicos.lotes import *
from django import forms
from django.db import models
from django.utils.translation import ugettext_lazy as _
from datetime import datetime
from cms.models import CMSPlugin
from djangocms_text_ckeditor.fields import HTMLField
class LoteDestaqueTest():
lotes = lotes.buscaLotes()
lote_id = forms.ChoiceField(choices=(lotes))
nome = models.CharField(max_length=150, verbose_name = _('Nome'))
imagem = models.CharField(max_length=200, verbose_name = _('Imagem'), blank=True, null=True)
observacoes = models.CharField(max_length=200, verbose_name = _('Observações'), blank=True, null=True)
descricao = HTMLField(verbose_name = _('Descrição'), blank=True, null=True)
valor = models.DecimalField(max_digits=9, decimal_places=2, verbose_name = _('Valor'), blank=True, null=True)
origem = models.CharField(max_length=50, verbose_name = _('Origem'), blank=True, null=True)
tipo = models.CharField(max_length=50, verbose_name = _('Tipo'), blank=True, null=True)
data_exposicao = models.DateTimeField(verbose_name = _('Data Exposição'), blank=True, null=True)
ativo = models.BooleanField(default=True, verbose_name = _('Ativo'), blank=True)
criado = models.DateTimeField(auto_now=True, editable=False, blank=True, null=True)
atualizado = models.DateTimeField(auto_now=True, editable=False, blank=True, null=True)
def __str__(self):
return self.nome
class Meta:
verbose_name = _('Lote em Destaque Test')
verbose_name_plural = _('Lotes em Destaque Test')
我的apps.py
from django.apps import AppConfig
class LoteLeiloesConfig(AppConfig):
name = 'leiloes_lotes_plugin'
这是 settings.py
中的集成
INSTALLED_APPS = (
'leiloes_lotes_plugin.apps.LoteLeiloesConfig',
'djangocms_admin_style',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
'django.contrib.messages',
'cms',
'menus',
'sekizai',
'treebeard',
'djangocms_text_ckeditor',
'filer',
'easy_thumbnails',
'djangocms_column',
'djangocms_link',
'cmsplugin_filer_file',
'cmsplugin_filer_folder',
'cmsplugin_filer_image',
'cmsplugin_filer_utils',
'djangocms_style',
'djangocms_snippet',
'djangocms_googlemap',
'djangocms_video',
'projeto'
)
任何帮助都是有用的。
如果您想要达到的目标是拥有一个像 class 这样的 ModelAdmin,这样您就可以在处理远程资源(通过 API)时获得 django-admin 的优势,您可以尝试: https://github.com/mbylstra/django-wham 该项目最后一次提交是在 2015 年,我希望这可以帮助您应对这一挑战。
看看这个问题:Map Django Model to External API
我是 Django 和 Python 的新手,我开始使用 Django CMS 使用此技术开发 CMS。
我需要创建一个模型管理页面来管理我的地块实体,但我的数据库中没有这个实体。基本上我会在索引列表中显示所有实体,像请求一样使用另一个服务。这是其他 CRUD 的想法。
当 create
、update
、delete
时,我将使用服务来对相应的实体进行此操作。为此,我将覆盖 admin.ModelAdmin
的 CRUD 方法。
有办法吗?
我到处找,但没有答案。
这是我已有的。
在我的admin.py
from django.contrib import admin
from cms.extensions import PageExtensionAdmin
from .models import LoteDestaque
from .models import LoteDestaqueTest
# from myproject.admin_site import custom_admin_site
@admin.register(LoteDestaqueTest)
这是我的 models.py
from .servicos.lotes import *
from django import forms
from django.db import models
from django.utils.translation import ugettext_lazy as _
from datetime import datetime
from cms.models import CMSPlugin
from djangocms_text_ckeditor.fields import HTMLField
class LoteDestaqueTest():
lotes = lotes.buscaLotes()
lote_id = forms.ChoiceField(choices=(lotes))
nome = models.CharField(max_length=150, verbose_name = _('Nome'))
imagem = models.CharField(max_length=200, verbose_name = _('Imagem'), blank=True, null=True)
observacoes = models.CharField(max_length=200, verbose_name = _('Observações'), blank=True, null=True)
descricao = HTMLField(verbose_name = _('Descrição'), blank=True, null=True)
valor = models.DecimalField(max_digits=9, decimal_places=2, verbose_name = _('Valor'), blank=True, null=True)
origem = models.CharField(max_length=50, verbose_name = _('Origem'), blank=True, null=True)
tipo = models.CharField(max_length=50, verbose_name = _('Tipo'), blank=True, null=True)
data_exposicao = models.DateTimeField(verbose_name = _('Data Exposição'), blank=True, null=True)
ativo = models.BooleanField(default=True, verbose_name = _('Ativo'), blank=True)
criado = models.DateTimeField(auto_now=True, editable=False, blank=True, null=True)
atualizado = models.DateTimeField(auto_now=True, editable=False, blank=True, null=True)
def __str__(self):
return self.nome
class Meta:
verbose_name = _('Lote em Destaque Test')
verbose_name_plural = _('Lotes em Destaque Test')
我的apps.py
from django.apps import AppConfig
class LoteLeiloesConfig(AppConfig):
name = 'leiloes_lotes_plugin'
这是 settings.py
INSTALLED_APPS = (
'leiloes_lotes_plugin.apps.LoteLeiloesConfig',
'djangocms_admin_style',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
'django.contrib.messages',
'cms',
'menus',
'sekizai',
'treebeard',
'djangocms_text_ckeditor',
'filer',
'easy_thumbnails',
'djangocms_column',
'djangocms_link',
'cmsplugin_filer_file',
'cmsplugin_filer_folder',
'cmsplugin_filer_image',
'cmsplugin_filer_utils',
'djangocms_style',
'djangocms_snippet',
'djangocms_googlemap',
'djangocms_video',
'projeto'
)
任何帮助都是有用的。
如果您想要达到的目标是拥有一个像 class 这样的 ModelAdmin,这样您就可以在处理远程资源(通过 API)时获得 django-admin 的优势,您可以尝试: https://github.com/mbylstra/django-wham 该项目最后一次提交是在 2015 年,我希望这可以帮助您应对这一挑战。
看看这个问题:Map Django Model to External API