How change the name of participants and keys in two-phase and three-phase project

This operation refers two documents named (views.py and urls.py)

step_1 open the views.py and add a function that could change the name of participants and keys

  • Notice: when you want to change the name of participants in file of two-phase, you will find two documents in this file. But when you would like to alter the name in file of three-phase, you will need to find and change the two documents in the three-phase file.

1. The next code could be used in two-phase file in views.py

def update_value(request):
    for num in range(1, 5):
        values = TwoPhaseValue.objects.filter(id = num).update(key = 'height')
    for num in range(5, 9):
        values = TwoPhaseValue.objects.filter(id = num).update(key = 'weight')
    TwoPhaseParticipant.objects.filter(id = 1).update(name = 'participant_1')
    TwoPhaseParticipant.objects.filter(id = 2).update(name = 'participant_2')
    TwoPhaseParticipant.objects.filter(id = 3).update(name = 'participant_3')
    TwoPhaseParticipant.objects.filter(id = 4).update(name = 'participant_4')

There are some notations for the above codes:

  1. the first class TwoPhaseValue is designed in models.py, you could find its attributes in this documents.
  2. if you just like to change its corresponding name, you just alter the content in string data type.
  3. if you add or delete some new data in your db.squlite3, you may to check out the value in your database’s corresponding id.
    *The next I will tell you how to use your command line to check out the content in database document *
    1.(base) C:\Users\Documents\GitHub\twophase-threephase-commit>dir(use the dir to see files in your current directory)
    2. find a document named db.sqlite3 and use the ordersqlite3 db.sqlite3
    3. you will enter the database, now you could use .tablesto see the tables in your database
    4. if you want to see the contents in twophase_twophaseparticipant, you could use select*from twophase_twophaseparticipant;and you will get the results like this:
    1|participant_1|0
    2|participant_2|0
    3|participant_3|0
    4|participant_4|0
    2.When you have done some changes in your views.py, you must add a order path('update_value', views.update_value, name='update_value'), in your urls.py
    3. you could add http://localhost:8000/two-phase/update_value in your browser, you will alter the name of the participants and keys successfully.

Guess you like

Origin blog.csdn.net/weixin_38396940/article/details/121726533