13.需求:在后台可以控制网格长和网格员在小程序端对数据的编辑权限
1.在NewCenter项目apps/user_operations/models.py中增加OnOrOff
class OnOrOff(models.Model): """数据操作开关""" wgz=models.BooleanField(default=False,verbose_name='是否开通网格长权限') wgy=models.BooleanField(default=False,verbose_name='是否开通网格员权限') add_time = models.DateTimeField(default=datetime.now, verbose_name="添加时间") class Meta: verbose_name = "权限开关表" verbose_name_plural = verbose_name
执行数据更新命令:
python manage.py makemigrations
python manage.py migrate
2.在apps/user_operations/serializers.py中:
from rest_framework import serializers from .models import Notice,OnOrOff class NoticeModelSerializer(serializers.ModelSerializer): class Meta: model = Notice fields="__all__" class OnOrOffModelSerializer(serializers.ModelSerializer): class Meta: model = OnOrOff fields="__all__"
3.在apps/user_operations/views.py中增加查看权限类EditPowerView:
class EditPowerView(APIView): """查看网格长和网格员是否有权限编辑数据""" def get(self, request): powr=OnOrOff.objects.all().last() re=OnOrOffModelSerializer(powr) return Response(re.data)
4.在NewCenter/urls.py中:
from django.urls import path from .views import GetPianQuBannerView,GetNoticeListView,UserLoginView,UpPwdView,GetCaoZuoView,UpUserInfoView,EditPowerView urlpatterns = [ path('getbanner/',GetPianQuBannerView.as_view()),#手机端获取banner图 path('getnoticeclist/',GetNoticeListView.as_view()),#获取公告列表 path('userlogin/',UserLoginView.as_view()),#小程序用户登录 path('uppwd/',UpPwdView.as_view()),#用户修改密码 path('getcaozuo/',GetCaoZuoView.as_view()),#获取操作数据 path('upuserinfo/',UpUserInfoView.as_view()),#更新用户个人信息 path('editpower/',EditPowerView.as_view()),#查看网格长和网格员是否有编辑权 ]
5.在xadmin后台,增加一条记录: