您好我有以下Admin.py
from portfolio.models import LandingPage, Galleries
from django.contrib import admin
from mezzanine.pages.models import Page, RichTextPage, Link
from mezzanine.core.admin import DisplayableAdmin
from mezzanine.utils.urls import admin_url
class GalleriesInline(admin.StackedInline):
model= Galleries.galleries.through
list_display = ('galleries','thumb')
class PortfolioAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields':['gallerytitle']})
]
inlines = [GalleriesInline]
admin.site.register(LandingPage, PortfolioAdmin)
这是我的model.py
from django.db import models
from mezzanine.pages.models import Page
from mezzanine.galleries.models import Gallery, GalleryImage
class LandingPage(models.Model):
gallerytitle = models.CharField(max_length=200)
def __unicode__(self):
return self.name
class Galleries(LandingPage):
landingpage = models.ForeignKey(LandingPage, related_name='lan_page')
#galleriesthumb = models.ForeignKey(GalleriesThumb)
tagline = models.CharField(max_length=100)
gallery = models.ManyToManyField(Gallery, related_name='gallerys')
thumb = models.ManyToManyField(GalleryImage)
def __unicode__(self):
return self.name
当我尝试通过管理员添加新的“LandingPage”时,我得到:
Environment:
Request Method: GET
Request URL: http://localhost:8000/admin/portfolio/landingpage/add/
Django Version: 1.4.2
Python Version: 2.7.3
Installed Applications:
['mezzanine.boot',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.redirects',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
'mezzanine.conf',
'mezzanine.core',
'mezzanine.generic',
'mezzanine.blog',
'mezzanine.forms',
'mezzanine.pages',
'mezzanine.galleries',
'mezzanine.twitter',
'portfolio',
'debug_toolbar',
'django.contrib.admin',
'django.contrib.comments']
Installed Middleware:
['debug_toolbar.middleware.DebugToolbarMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'mezzanine.core.request.CurrentRequestMiddleware',
'mezzanine.core.middleware.TemplateForDeviceMiddleware',
'mezzanine.core.middleware.TemplateForHostMiddleware',
'mezzanine.core.middleware.AdminLoginInterfaceSelectorMiddleware',
'mezzanine.pages.middleware.PageMiddleware']
Traceback:
File "/home/grumps/.virtualenvs/ofmax/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
89. response = middleware_method(request)
File "/home/grumps/.virtualenvs/ofmax/local/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/grumps/projects/ofmax/urls.py" in <module>
8. admin.autodiscover()
File "/home/grumps/projects/ofmax/mezzanine/boot/__init__.py" in autodiscover
76. django_autodiscover(*args, **kwargs)
File "/home/grumps/.virtualenvs/ofmax/local/lib/python2.7/site-packages/django/contrib/admin/__init__.py" in autodiscover
29. import_module('%s.admin' % app)
File "/home/grumps/.virtualenvs/ofmax/local/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/grumps/projects/ofmax/portfolio/admin.py" in <module>
8. class GalleriesInline(admin.StackedInline):
File "/home/grumps/projects/ofmax/portfolio/admin.py" in GalleriesInline
9. model= Galleries.galleries.through
Exception Type: AttributeError at /admin/portfolio/landingpage/add/
Exception Value: 'SingleRelatedObjectDescriptor' object has no attribute 'through'
我正在尝试将管理员设置为显示所有图库的实例,并选择一个图库以便能够选择与图库相关的GalleryImage
如果这是一个愚蠢的问题,我道歉。我是新人,我正在尝试解决这个问题,但我被困住了。