parent
3fca0a1b0a
commit
b1f7b06092
|
@ -32,9 +32,7 @@ class UserSerializer(CustomModelSerializer):
|
||||||
|
|
||||||
def get_role_info(self, instance, parsed_query):
|
def get_role_info(self, instance, parsed_query):
|
||||||
roles = instance.role.all()
|
roles = instance.role.all()
|
||||||
|
|
||||||
# You can do what ever you want in here
|
# You can do what ever you want in here
|
||||||
|
|
||||||
# `parsed_query` param is passed to BookSerializer to allow further querying
|
# `parsed_query` param is passed to BookSerializer to allow further querying
|
||||||
serializer = RoleSerializer(
|
serializer = RoleSerializer(
|
||||||
roles,
|
roles,
|
||||||
|
|
|
@ -30,6 +30,7 @@ class CoreModel(models.Model):
|
||||||
update_datetime = models.DateTimeField(auto_now=True, null=True, blank=True, help_text="修改时间", verbose_name="修改时间")
|
update_datetime = models.DateTimeField(auto_now=True, null=True, blank=True, help_text="修改时间", verbose_name="修改时间")
|
||||||
create_datetime = models.DateTimeField(auto_now_add=True, null=True, blank=True, help_text="创建时间",
|
create_datetime = models.DateTimeField(auto_now_add=True, null=True, blank=True, help_text="创建时间",
|
||||||
verbose_name="创建时间")
|
verbose_name="创建时间")
|
||||||
|
is_deleted = models.BooleanField(verbose_name="是否软删除",help_text='是否软删除', default=False, db_index=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
|
@ -43,7 +43,11 @@ class CustomModelViewSet(ModelViewSet,ImportSerializerMixin,ExportSerializerMixi
|
||||||
def filter_queryset(self, queryset):
|
def filter_queryset(self, queryset):
|
||||||
for backend in set(set(self.filter_backends) | set(self.extra_filter_backends or [])):
|
for backend in set(set(self.filter_backends) | set(self.extra_filter_backends or [])):
|
||||||
queryset = backend().filter_queryset(self.request, queryset, self)
|
queryset = backend().filter_queryset(self.request, queryset, self)
|
||||||
|
request_query =self.request.query_params
|
||||||
|
is_deleted = request_query.get('is_deleted',None)
|
||||||
|
if is_deleted:
|
||||||
return queryset
|
return queryset
|
||||||
|
return queryset.exclude(is_deleted=True)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
if getattr(self, 'values_queryset', None):
|
if getattr(self, 'values_queryset', None):
|
||||||
|
@ -92,6 +96,12 @@ class CustomModelViewSet(ModelViewSet,ImportSerializerMixin,ExportSerializerMixi
|
||||||
|
|
||||||
def destroy(self, request, *args, **kwargs):
|
def destroy(self, request, *args, **kwargs):
|
||||||
instance = self.get_object()
|
instance = self.get_object()
|
||||||
|
request_data = request.data
|
||||||
|
soft_delete = request_data.get('softDelete',None)
|
||||||
|
if soft_delete:
|
||||||
|
instance.is_deleted=True
|
||||||
|
instance.save()
|
||||||
|
else:
|
||||||
self.perform_destroy(instance)
|
self.perform_destroy(instance)
|
||||||
return DetailResponse(data=[], msg="删除成功")
|
return DetailResponse(data=[], msg="删除成功")
|
||||||
|
|
||||||
|
|
|
@ -256,6 +256,10 @@ Vue.prototype.commonEndColumns = function (param = {}) {
|
||||||
create_datetime: {
|
create_datetime: {
|
||||||
showForm: (param.create_datetime && param.create_datetime.showForm) !== undefined ? param.create_datetime.showForm : false,
|
showForm: (param.create_datetime && param.create_datetime.showForm) !== undefined ? param.create_datetime.showForm : false,
|
||||||
showTable: (param.create_datetime && param.create_datetime.showTable) !== undefined ? param.create_datetime.showTable : true
|
showTable: (param.create_datetime && param.create_datetime.showTable) !== undefined ? param.create_datetime.showTable : true
|
||||||
|
},
|
||||||
|
is_deleted: {
|
||||||
|
showForm: (param.is_deleted && param.is_deleted.showForm) !== undefined ? param.is_deleted.showForm : false,
|
||||||
|
showTable: (param.is_deleted && param.is_deleted.showTable) !== undefined ? param.is_deleted.showTable : false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
|
@ -388,6 +392,23 @@ Vue.prototype.commonEndColumns = function (param = {}) {
|
||||||
form: {
|
form: {
|
||||||
disabled: !showData.create_datetime.showForm
|
disabled: !showData.create_datetime.showForm
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '是否软删除',
|
||||||
|
key: 'is_deleted',
|
||||||
|
width: 160,
|
||||||
|
search: {
|
||||||
|
disabled: !showData.is_deleted.showForm,
|
||||||
|
},
|
||||||
|
show: showData.is_deleted.showTable,
|
||||||
|
type: 'radio',
|
||||||
|
dict:{
|
||||||
|
data:[{label:"是",value:true},{label:"否",value:false}]
|
||||||
|
},
|
||||||
|
sortable: true,
|
||||||
|
form: {
|
||||||
|
disabled: !showData.is_deleted.showForm
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ export function GetList (query) {
|
||||||
return request({
|
return request({
|
||||||
url: urlPrefix,
|
url: urlPrefix,
|
||||||
method: 'get',
|
method: 'get',
|
||||||
params: query
|
params: { ...query }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ export function DelObj (id) {
|
||||||
return request({
|
return request({
|
||||||
url: urlPrefix + id + '/',
|
url: urlPrefix + id + '/',
|
||||||
method: 'delete',
|
method: 'delete',
|
||||||
data: { id }
|
data: { softDelete: true }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue