Django 后台定制自己的选择框删除函数
Posted sunshenggang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django 后台定制自己的选择框删除函数相关的知识,希望对你有一定的参考价值。
from django.contrib import admin from .models import Article,Category from datetime import datetime # Register your models here. @admin.register(Article) class ArticleAdmind(admin.ModelAdmin): list_display = [‘id‘,‘title‘,‘add_time‘,‘state‘] list_display_links = (‘id‘, ‘title‘) search_fields = (‘title‘,) #定制搜索 #def get_search_results(self,request,queryset,search_term): # queryset,use_distinct = super(ArticleAdmind,self).get_search_results(request,queryset,search_term) def delete_queryset(self, request, queryset): """ Given a queryset, delete it from the database. 重新修改删除操作 """ # if queryset.count() == 1: # obj = queryset.get() # obj.state = 0 # obj.update_time = datetime.now # obj.save() # else: for obj in queryset.filter(): obj.state = 0 obj.update_time = datetime.now() obj.save() #print(dir(queryset)) #print(queryset.filter()) def save_model(self, request, obj, form, change): """ Given a model instance save it to the database. 重新写修改或者保存操作 如果是新加 obj.id 返回None """ obj.save() @admin.register(Category) class CategoryAdmin(admin.ModelAdmin): list_display = [‘id‘,‘name‘,‘add_time‘]
以上是关于Django 后台定制自己的选择框删除函数的主要内容,如果未能解决你的问题,请参考以下文章