django filter_horizo​​ntal无法显示 [英] django filter_horizontal can't display

查看:42
本文介绍了django filter_horizo​​ntal无法显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是模特:

author = models.ManyToManyField(Author)

modelAdmin: filter_horizo​​ntal =(作者",)

modelAdmin: filter_horizontal=("author",)

它仍在呈现多选小部件.我不知道怎么了.

It's still rendering a multiple select widget. I don't know what's the problem.

Django 1.5.

Django 1.5.

mysite/mysite/views.py

mysite/mysite/views.py

from django.shortcuts import render_to_response
from django.http import HttpResponse,Http404
import datetime

def hello(request):
    return HttpResponse("Hello world")

def current_time(request):
    now=datetime.datetime.now()
    return render_to_response('current_datetime.html',{'current_date':now})#(template,context) ADDED BY ROBERT

def hours_ahead(request,offset):
    try:
    offset=int(offset)
    except ValueError:
    raise Http404()
    dt=datetime.datetime.now()+datetime.timedelta(hours=offset)
    html='In %d hours, it will be %s.'%(offset,dt)
    return HttpResponse(html)

def display_meta(request):
    values=request.META.items()
    values.sort()
    html=[]
    for k,v in values:
    html.append('<tr><td>%s</td><td>%s</td></tr>'%(k,v))
    return HttpResponse('<table>%s</table>' % '\n'.join(html))

mysite/mysite/urls.py

mysite/mysite/urls.py

from django.conf.urls import patterns, include, url
from mysite.views import *
#from books import views
from books import views

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    ('^hello/$',hello),
    ('^time/$',current_time),
    (r'^time/(\d{1,2})/$',hours_ahead),
    (r'^admin/',include(admin.site.urls)),
    (r'^display_meta/$',display_meta),
    (r'^search/$',views.search),
)

mysite/books/models.py

mysite/books/models.py

from django.db import models
from django.contrib import admin

# Create your models here.

class Publisher(models.Model):
    name=models.CharField(max_length=30)
    address=models.CharField(max_length=50)
    city=models.CharField(max_length=60)
    state_province=models.CharField(max_length=30)
    country=models.CharField(max_length=30)
    website=models.URLField()

    def __unicode__(self):
    return self.name

class Author(models.Model):
    first_name=models.CharField(max_length=30)
    last_name=models.CharField(max_length=30)
    email=models.EmailField(blank=True,verbose_name='e-mail')
    def __unicode__(self):
    return u'%s %s' %(self.first_name,self.last_name)

class AuthorAdmin(admin.ModelAdmin):
    list_display=('first_name','last_name','email')
    search_fields=('first_name','last_name')

class Book(models.Model):
    name=models.CharField(max_length=100)
    author=models.ManyToManyField(Author)
    publisher=models.ForeignKey(Publisher)
    publication_date=models.DateField(null=True,blank=True,verbose_name='Publication Date')
    def __unicode__(self):
    return u'%s' % self.name

class BookAdmin(admin.ModelAdmin):
    list_display=('name','publisher','publication_date')
    list_filter=('publication_date',)
    ordering=('-publication_date',)
    date_hierachy='publication_date'
#fields=('name','author','publisher','publication_date')
    filter_horizontal=('author',)

admin.py

from django.contrib import admin
from books.models import *

admin.site.register(Publisher)
admin.site.register(Author,AuthorAdmin)
admin.site.register(Book,BookAdmin)

推荐答案

我认为答案为时已晚.但是,我在阅读django核心书籍时遇到了同样的问题,我认为这可能是您提出问题的原因:

I think it's too late to answer; however, I ran into the same problem while reading django-core book which I think might be the source of your question:

只需在隐身模式下或在其他浏览器中打开管理面板,就可以通过从浏览器中删除缓存的内容来解决此问题.我认为问题可能是由于您在进行更改之前第一次未完全加载javascript.然而;以隐身-私人模式打开它为我解决了这个问题.

simply open the admin panel in incognito mode or in another browser, you can also get rid of the problem by removing cached content from your browser. I think the problem might stem from javascript incomplete loading for the first time prior to the changes you made. However; opening it in incognito-private mode solved the problem for me.

这篇关于django filter_horizo​​ntal无法显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆