change the name of participants and keys in three phases

本文介绍了如何在网站上通过删除特定ID的值并更新参与者名称,展示了在views.py中`delete_value`和`update_name`函数的实现。通过URL路由,访问这些功能并观察数据库变化,涉及的技术包括数据库操作和前后端交互。
摘要由CSDN通过智能技术生成

detained steps

When you input the website address: http://localhost:8000/three-phase/ you will get the next interface:
picture_1

  • Now you may want to make it more observable, you need to delete a attributes named hhh. What can you do?
    1. find the ID number of hhh in your database: you will get the final results (use the same way taught before)
  • 在这里插入图片描述
  • Now, you will find the ID numbers of hhh are 17, 18, 19, 20
  • design a delete_key() function in vews.py and use path function to add it into urls.py
  • The function added in vews.py:
def delete_value(request):
    for num in range(17, 21):
        data = ThreePhaseValue.objects.get(id = num)
        data.delete()
    return app_page(request)

The next order path('delete_value', views.delete_value, name='delte_value'), in urls.py
When you access the website by inputting http://localhost:8000/three-phase/delete_value
into your browser. You will get the next results:
在这里插入图片描述
When you access your database again, you will find the following results:
在这里插入图片描述
original picture

The next is how to change the name of the participants:

  1. step_1 find the corresponding id for participants’ name
    1|ruan|0
    2|sun1|0
    3|huang|0
    4|wang|0
  2. the codes written in the views.py
def update_name(request):
    participant = ThreePhaseParticipant.objects.filter(id=1).update(name = 'participant_1')
    participant = ThreePhaseParticipant.objects.filter(id=2).update(name = 'participant_2')
    participant = ThreePhaseParticipant.objects.filter(id=3).update(name = 'participant_3')
    participant = ThreePhaseParticipant.objects.filter(id=4).update(name = 'participant_4')
    for num in range(1, 5):
        value = ThreePhaseValue.objects.filter(id = num).update(key = 'height')
    for num in range(5, 9):
        value = ThreePhaseValue.objects.filter(id = num).update(key = 'weight')
    return app_page(request)
  1. The codes added in the urls.py path('update_name', views.update_name, name='update_name'),and you will get
    在这里插入图片描述
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值