大佬教程收集整理的这篇文章主要介绍了如何从 django admin 中的新应用程序查看模型?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在 django 上与管理员一起使用电报机器人。项目中有 7 个应用程序。我创建新应用程序,在应用程序中的 admin.py 中注册模型,在 setTings.py 中编写应用程序,进行迁移和迁移,重新启动主管,在此之下一切正常,但什么也没有。管理路径是使用 django-admin-tools 创建的。我全部返回到标准 django 管理员,但管理员中的模型无法查看。不知道还有什么可以赚更多。
INSTALLED_APPS = [
'admin_tools','admin_tools.theming','admin_tools.menu','admin_tools.dashboard','mptt',"django_cron",'django.contrib.admin','django.contrib.auth','django.contrib.ContentTypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','django.contrib.POSTGRes','django.contrib.humanize','cache_model','preferences','public_model','sort_model','users','server_resources','application.telegram','application.request','application.trucks','application.SALEs','application.parsings','application.docs','application.raTing','application.check','application.subscription','application.emirates'
]
MIDDLEWARE = [
'django.mIDdleware.security.SecuritymIDdleware','django.contrib.sessions.mIDdleware.SessionMIDdleware','django.mIDdleware.common.CommonMIDdleware','django.mIDdleware.csrf.CsrfVIEwMIDdleware','django.contrib.auth.mIDdleware.AuthenticationMIDdleware','django.contrib.messages.mIDdleware.messageMIDdleware','django.mIDdleware.clickjacking.XFrameOptionsMIDdleware',]
ROOT_URLconf = 'application.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.BACkends.django.DjangoTemplates','Dirs': [os.path.join(BASE_DIR,'templates'),],'APP_Dirs': false,'OPTIONS': {
'context_processors': [
'django.template.context_processors.deBUG','django.template.context_processors.i18n','django.template.context_processors.media','django.template.context_processors.request','django.template.context_processors.static','django.contrib.messages.context_processors.messages','django.contrib.auth.context_processors.auth','loaders': [
'django.template.loaders.filesystem.Loader','django.template.loaders.app_directorIEs.Loader','admin_tools.template_loaders.Loader','deBUG': DEBUG,},]
Wsgi_APPliCATION = 'application.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/ref/setTings/#databases
# Database
DATABASES = {
'default': {
'ENGINE': 'django.db.BACkends.POSTGResql_psycopg2','name': 'telegram_avtorazborov_bot','USER': 'POSTGRes','passworD': 'POSTGRes','HOST': 'localhost','PORT': '',}
}
# password valIDation
# https://docs.djangoproject.com/en/1.11/ref/setTings/#auth-password-valIDators
AUTH_password_VALIDATORS = [
]
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'ru-ru'
TIME_ZONE = 'Europe/Moscow'
USE_I18N = True
USE_L10N = True
USE_TZ = false
LOCALE_PATHS = (os.path.join(BASE_DIR,'locale'),)
# Static files (CSS,JavaScript,Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'..','static')
STATICfileS_Dirs = (os.path.join(BASE_DIR,'static'),)
MEDIA_ROOT = os.path.join(BASE_DIR,'media')
MEDIA_URL = '/media/'
admin_MEDIA_PREFIX = '/static/admin/'
# admin tools setTings
admin_TOolS_INDEX_DASHBOARD = 'application.dashboard.CustomIndexDashboard'
admin_TOolS_MENU = 'application.menu.CustomMenu'
admin_TOolS_THEMING_CSS = 'admin/CSS/theming.CSS'
admin.py(应用内):
class EmirateImageInlineTabularadmin(admin.TabularInlinE):
model = EmirateImage
fIElds = ('image',)
extra = 0
@public_model
@admin.register(EmiratE)
class Emirateadmin(admin.Modeladmin):
List_display = ('name','price',)
List_display_links = ('name',)
fIEldsets = (
(None,{
'fIElds': ('price','name',)
}),)
search_fIElds = ['name','price__name']
List_filter = ('price',)
def text_format(self,obj):
return obj.text[:100]
text_format.short_description = _('Decription')
List_display = ('type','decription','weight',)
List_display_links = ('type',{
'fIElds': ('type',)
search_fIElds = ['type','name']
Readonly_fIElds = []
date_hIErarchy = 'date_create'
raw_ID_fIElds = ['name']
List_SELEct_related = ('name','name__price','weight')
inlines = [EmirateImageInlineTabularadmin,]
@H_407_2@models.py(在应用程序中):
from django.db import models
from django.utils.translation import ugettext_lazy as _
from public_model.models import PublicModel
from application.telegram.models import User
class Emirate(PublicModel,models.Model):
types = (
('motors',_('motors')),('Boxes',_('Boxes')),)
type = models.CharFIEld(_('Type'),blank=True,choices=types,null=True,max_length=20)
name = models.CharFIEld(_('Emirates motors'),max_length=1000,null=TruE)
decription = models.TextFIEld(_('Text'))
price = models.floatFIEld(_('Motors price'))
weight = models.floatFIEld(_('Motors weight'))
class Meta:
db_table = 'emirates'
ordering = ['-price']
verbose_name = _('Emirate')
verbose_name_plural = _('Emirates')
def __str__(self):
return self.name#'%s' % self.name
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的如何从 django admin 中的新应用程序查看模型?全部内容,希望文章能够帮你解决如何从 django admin 中的新应用程序查看模型?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。