简体   繁体   English

Django 1.6.4 list_filter

[英]django 1.6.4 list_filter

I'm using Django 1.6.4 with Python 3.3. 我正在将Django 1.6.4与Python 3.3配合使用。 I would like to have, in my admin page, a Search menu to find a name in my table. 我想在我的管理页面中找到一个“搜索”菜单,以在表中查找名称。 My project is 'prova' and the model is 'pazienti'. 我的项目是“ prova”,模型是“ pazienti”。 I used this code in models.py: 我在models.py中使用了以下代码:

from django.db import models
from django.contrib import admin
from prova.pazienti.models import *

class Patient(models.Model):
    name = models.CharField(max_length=60)
    surname = models.CharField(max_length=60)
    data_nascita = models.DateField()


class Admin:
    list_display=('name','surname')
    list_filter=('surname',)
    search_fields=('surname',)

But... it doesn't work! 但是...这不起作用! I tried also do not insert class Admin in models.py but insert this in admin.py: 我试过也不要在models.py中插入Admin类,而是在admin.py中插入:

from django.contrib import admin
from django.contrib.admin import SimpleListFilter
from django.utils.translation import ugettext_lazy as _
from prova.pazienti.models import *

class PatientAdmin(admin.ModelAdmin):
    list_display=('numero_centro','matricola_pz_centro')
    list_filter=('numero_centro',)
    search_fields=('numero_centro',)

admin.site.register(Patient, PatientAdmin)

admin.site.unregister(Patient)

But the result is the same: no error but I haven't the search bar! 但是结果是一样的:没有错误,但是我没有搜索栏! Can you help me? 你能帮助我吗?

Thank you! 谢谢!

Ok, I find... The code is correct, only in some previous exercise I insert: 好的,我发现...该代码是正确的,仅在以前的一些练习中才插入:

admin.site.register(Patient)

in urls.py, so all things wrote in admin.py were ignored! 在urls.py中,因此忽略了在admin.py中编写的所有内容! Sorry and thank you 对不起,谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM