detained steps
When you input the website address: http://localhost:8000/three-phase/
you will get the next interface:
- Now you may want to make it more observable, you need to delete a attributes named hhh. What can you do?
-
- 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:
The next is how to change the name of the participants:
- step_1 find the corresponding id for participants’ name
1|ruan|0
2|sun1|0
3|huang|0
4|wang|0 - 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)
- The codes added in the urls.py
path('update_name', views.update_name, name='update_name'),
and you will get