Django备忘
Page content
这几项操作将你效率倍增
0x00 命令行操作
1.数据导出
python manage.py dumpdata > data.json
2.数据导入
python manage.py loaddata data.json
3.排除空记录
model.objects.exclude(alias__isnull=True).exclude(alias__exact='')
4.DRF关闭CSRF
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
)
}
0x01 类字段额外解析开启
exact,iexact,gt,gte,lt,lte,in,contains,icontains,startswith,istartswith,endswith,iendswith,range,isnull,regex,iregex
class AnyModelFilter(filters.FilterSet):
class Meta:
model = AnyModel
fields = '__all__'
@classmethod
def get_fields(cls):
fields = super().get_fields()
for field_name in fields.copy():
lookup_list = cls.Meta.model._meta.get_field(field_name).get_lookups().keys()
fields[field_name] = lookup_list
return fields
0x03 类额外Meta
# models.py
import django.db.models.options as options
options.DEFAULT_NAMES = options.DEFAULT_NAMES + ('table_cols','form_cols','export_order',)