[英]Create model admin page without create table python
I'm new to Django and Python and am starting to develop a CMS with this technology with Django CMS. 我是Django和Python的新手,并且开始使用Django CMS使用此技术开发CMS。
I need to create a model admin page to manage my lots entity, but i will not have this entity in my database. 我需要创建一个模型管理页面来管理我的地块实体,但是我的数据库中将没有该实体。 Basically i will display all entities of lots in the index list, consuming another service like a request. 基本上,我将在索引列表中显示批次的所有实体,并使用其他服务(例如请求)。 And this is the idea for the other CRUD's. 这就是其他CRUD的想法。
When create
, update
, delete
I will consume a service to make this operations with the respective entity. 当create
, update
, delete
我将使用服务对相应实体进行此操作。 For this I will override the CRUD methods of admin.ModelAdmin
. 为此,我将覆盖admin.ModelAdmin
的CRUD方法。 Is there a way to do that? 有没有办法做到这一点?
I looked everywhere but without answers. 我到处看,但没有答案。
This is what I already have. 这就是我已经拥有的。
In my admin.py
在我的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)
Here is my models.py
这是我的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')
My apps.py
我的apps.py
from django.apps import AppConfig
class LoteLeiloesConfig(AppConfig):
name = 'leiloes_lotes_plugin'
And here is the integration in settings.py
这是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'
)
Any help is usefull. 任何帮助都是有用的。
If what you are trying to reach is to have a ModelAdmin like class so you can get the advantages of django-admin while you handle remote resources (via API), you can try: https://github.com/mbylstra/django-wham the project last commit was in 2015, I hope this can help you in how to tackle this challenge. 如果您要达到的目标是拥有像ModelAdmin这样的类,以便在处理远程资源(通过API)时获得django-admin的优势,则可以尝试: https : //github.com/mbylstra/django-威猛该项目最后一次提交的是2015年,我希望这可以帮助你在如何应对这种挑战。
Check out this question: Map Django Model to External API 看看这个问题:将Django模型映射到外部API
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.