How do i trigger an operation if a button is clicked for the first time , but if pressed again do extra thing.
if request.method == 'POST': # if i press a button on the client side, (obj_list) return something like this [0.3, 2.32, 1.22] passed here through ajax (no problem here)
x = 1
obj_db = []
for obj_items in obj_list:
should_sum = False
while not should_sum:
x *= obj_items
#return only two decimal numbers after float number
new_obj_num = round(obj_total, 2)
obj_db.append(new_obj_num)
print('stored value : ', obj_db)
if object_selected:
obj_db += obj_items
else:
should_sum = True
now, when i click a button i need the obj_list data to get multiplied, and store the results in obj_db(which i've done). But when i click again (from client side), i need to multiply but sum with the previous stored results. Any Suggestions ??!
As we talked in the comments you need to save your counter to know how many times anyone clicked.
# try to read the counter stored in a file
try:
f = open("counter.txt", "r")
data_returned_as_str = f.read()
counter = int(data_returned_as_str)
except FileNotFoundError as e:
counter = 0
# do your stuff
counter += 1
f = open("counter.txt", "w") # use write to overwrite the last content
f.write(str(counter))
f.close()
print(counter)
If you also need the previous data write another file to read that.