gpt4 book ai didi

python - django filter_horizo​​ntal无法显示

转载 作者:行者123 更新时间:2023-11-30 23:34:21 25 4
gpt4 key购买 nike

这是模型:

author=models.ManyToManyField(作者)

模型管理员:filter_horizo​​ntal=("作者",)

它仍在渲染一个多选小部件。不知道出了什么问题。

Django 1.5。

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

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

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-core 书时遇到了同样的问题,我认为这可能是您问题的根源:

只需以隐身模式或其他浏览器打开管理面板,您也可以通过从浏览器中删除缓存内容来解决该问题。我认为问题可能源于在您进行更改之前第一次 JavaScript 加载不完整。然而;以隐身模式打开它解决了我的问题。

关于python - django filter_horizo​​ntal无法显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18164198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com