django admin에서 soft_delete 사용하기

hyuckhoon.ko·2021년 6월 22일
0

What I learned in first year

목록 보기
85/146
class ProductAdmin(ExportMixin, admin.ModelAdmin):



                       (중략)



    def delete_queryset(self, request, queryset):
        """상품 상태별 삭제 설정 변경"""
        
        for obj in queryset:
            if obj.product_status_id < 6:
                obj.soft_delete()
            else:
                obj.delete()
            

    def get_queryset(self, obj):
       qs = super(ProductAdmin, self).get_queryset(obj)
       return qs.exclude(is_deleted=True)

참고자료: https://stackoverflow.com/questions/56450998/is-there-a-way-to-override-the-delete-selected-method-in-modeladmin-but-keep-con

0개의 댓글