并非管理员中列出的所有项目

时间:2014-09-18 16:57:05

标签: django django-admin

我可以看到并非所有项目都显示在我的管理员中。我可以在网址中使用id打开它们,但它们未列出,因此我无法搜索和过滤它们。可能有什么不对?

列表页脚和标题中还有1735 results2519 total

以下是admin.py的样子:

class DetalAdminForm(ModelForm):
    class Meta:
        model = Detal
    def __init__(self, *args, **kwargs):
        if not kwargs.get('instance', None):
            if not kwargs.get('initial', None):
                kwargs['initial'] = {}
            if not kwargs['initial'].get('number', None):
                kwargs['initial']['number'] = get_first_unused_detal_number()
        super(DetalAdminForm, self).__init__(*args, **kwargs)

class CellListFilter(admin.SimpleListFilter):
    title = 'Ячейка (включая доп. места)'
    parameter_name = 'cell_number'

    def lookups(self, request, model_admin):
        cells_list = StoringCell.objects.all().values_list('id', 'number')
        return cells_list

    def queryset(self, request, queryset):
        cell_number = self.value()
        return queryset.filter(Q(cell__id=cell_number) | Q(dopolnenie__cell__id=cell_number)).distinct()

class DetalAdmin(admin.ModelAdmin):
    form = DetalAdminForm
    fieldsets = (
        (None, {'fields' : ['number']}),
        ('...', {'fields' : ['name', 'tipe', 'korpus', 'primechanie', ('cell', 'kol_nalicie', 'upakovka')]}),
        )
    search_fields = ['name']
    list_display = ('number', 'tipe', 'name', 'korpus', 'cell', 'kol_nalicie', 'get_adds_amount')
    list_display_links = ['number', 'tipe', 'name', 'korpus', 'cell', 'kol_nalicie']
    list_filter = ['da_net', 'tipe', 'korpus', 'cell', CellListFilter]
    list_select_related = True
    ordering = ['number']
    inlines = [DopolnenieInline, OpisanieInline, KodPostavInline]

前段时间我做了一些架构和数据迁移,也许我做错了什么?如果我做错了什么我仍然可以访问对象?

2 个答案:

答案 0 :(得分:0)

尝试在admin.py

中设置list_max_show_alllist_per_page

喜欢

class ArticleAdmin(admin.ModelAdmin):
    list_max_show_all = 3000
    list_per_page = 500

答案 1 :(得分:0)

问题在于自定义过滤器CellListFilter。我应该检查parameter_name中是否有request.GET

def queryset(self, request, queryset):
        if self.parameter_name in request.GET:
            cell_number = self.value()
            return queryset.filter(Q(cell__id=cell_number) | Q(dopolnenie__cell__id=cell_number)).distinct()
        return queryset