pip install django-bootstrap4
{% load bootstrap4 %}
{% bootstrap_css %}
{% bootstrap_javascript jquery='full' %}
利用__init__
的时候备份数据,实现知道一个model哪些数据变化了
设置一个model对象的权限
超级简单的利用middleware来查看请求耗时
sudo pip3 install django-performance-monitor
INSTALLED_APPS.append("django_performance_monitor")
MIDDLEWARE.append("django_performance_monitor.middleware.LogRequestMiddleware")
- 校验权限 user.has_perm("vip", obj)
- assign_perm(perm, user_or_group, obj)
- remove_perm(perm, user_or_group, obj)
from guardian.shortcuts import assign_perm, remove_perm
assign_perm("basic", user, obj)
remove_perm("basic", user, obj)
get_objects_for_user(user, "basic", ModelClass)
>>> return Queryset
- get_users_with_perms 获取有某个对象权限的用户
get_users_with_perms(obj)
利用post_save
来记录每一次的model变更
INSTALLED_APPS = [
# ...
'simple_history',
]
MIDDLEWARE = [
# ...
'simple_history.middleware.HistoryRequestMiddleware',
]
from simple_history.models import HistoricalRecords
class Model(models.Model):
history = HistoricalRecords(exclude_fields=["update_datetime"]) # maybe you don't need the update_datetime since the history model contains history_date
model = Model.objects.first()
model.history.latest()
model.as_of(datetime(2021, 1, 1, 0, 0, 0))
利用__init__
的时候备份数据,实现知道一个model哪些数据变化了
pip install django-bootstrap4
{% load bootstrap4 %}
{% bootstrap_css %}
{% bootstrap_javascript jquery='full' %}