2

我正在尝试扩展auth.User admin. 我想显示内联表单。我添加了以下代码。但是这段代码不起作用。我没有收到任何错误。当我单击任何特定用户的该页面时,该页面会继续加载。我错过了什么吗?谢谢

模型

class Reservation(models.Model):
    publisher = models.ForeignKey(User, null=False, blank=True)

管理员.py

from django.contrib.auth.admin import UserAdmin
class ReservationInline(admin.StackedInline):
    model = Reservation
    fk_name = 'publisher'

class CustomUserAdmin(UserAdmin):
    list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
    inlines = (ReservationInline,)

admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)

编辑 - 2 runserver 输出

75 查询奇怪。

DEBUG 2013-08-14 17:03:53,744 middleware 400 4424093696 4 queries run, total 0.041 seconds
[14/Aug/2013 17:03:53] "GET /admin/ HTTP/1.1" 200 2506
DEBUG 2013-08-14 17:03:57,405 middleware 400 4424093696 5 queries run, total 0.0 seconds
[14/Aug/2013 17:03:57] "GET /admin/auth/user/ HTTP/1.1" 200 1621
DEBUG 2013-08-14 17:03:57,568 middleware 400 4424093696 2 queries run, total 0.0 seconds
[14/Aug/2013 17:03:57] "GET /admin/jsi18n/ HTTP/1.1" 200 718
DEBUG 2013-08-14 17:07:38,668 middleware 400 4424093696 75 queries run, total 21.408 seconds
[14/Aug/2013 17:07:59] "GET /admin/auth/user/2/ HTTP/1.1" 200 10095678
DEBUG 2013-08-14 17:08:18,511 middleware 400 4424093696 2 queries run, total 1.143 seconds

编辑

我试过其他型号。他们工作正常。但如果我使用Reservation模型。这没用。:(

4

1 回答 1

1

如果您的数据库中有很多用户记录,那么如果您没有利用raw_id_fields属性,那么使用 Reservation 模型将导致页面在加载过程中出现很长的延迟。

尝试...

class ReservationInline(admin.StackedInline):
    model = Reservation
    fk_name = 'publisher'
    raw_id_fields = ('publisher',)
于 2013-08-18T22:32:52.403 回答