简体   繁体   English

Django-admin,按字段选择

[英]Django-admin, SELECT by fields

There is a UserTask module in which there are very heavy fields and they break the request, how can I remove them from the query for Django Admin. 有一个UserTask模块,其中有非常重的字段,它们破坏了请求,我如何从Django Admin查询中删除它们。

They do not appear on the page, but Django uses something like this: 它们没有出现在页面上,但是Django使用了类似这样的东西:

SELECT * FROM UserTask;

And you need: 并且您需要:

SELECT id, name, is_user FROM UserTask;

It is necessary to remove them in the admin area, here is the registration of the model: 有必要在管理区域中将其删除,这是模型的注册:

class UserTaskAdmin(admin.ModelAdmin):
    list_filter = ('id', 'name')
    list_display = ('id', 'name')    


admin.site.register(UserTask, UserTaskAdmin)

original version is russian . 原始版本是俄语

You can override get_queryset and use only method: 您可以覆盖get_querysetonly使用方法:

class UserTaskAdmin(admin.ModelAdmin):
    list_filter = ('id', 'name')
    list_display = ('id', 'name') 

    def get_queryset(self, request):
        return UserTask.objects.only('id', 'name')

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

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