def save_model(self, request, obj, form, change):
if 'total' in form.changed_data:
# В OrderItem.save обработайте параметр update_total
obj.save(update_total=False)
else:
obj.save(update_total=True)
def save_model(self, request, obj, form, change):
if 'total' in form.changed_data:
custom_total = obj.total
super().save_model(request, obj, form, change)
OrderItem.objects.filter(pk=obj.pk).update(total=custom_total)
else:
super().save_model(request, obj, form, change)
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get('http://www.seosprint.net/')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="mnu302"]'))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="content"]/div/form/input'))).click()
from urllib.parse import urlunparse, urlparse
from urllib.request import urlopen
url = 'http://сайт.рф'
scheme, netloc, path, params, query, fragment = urlparse(url)
url = urlunparse((scheme, netloc.encode('idna').decode('utf8'), path, params, query, fragment))
r = urlopen(url)
print(r.read()[0:50])
import os
path = "Q:\\Temp"
file = open('testfile.txt', 'w', encoding='utf8')
for dirpath, dirnames, filenames in os.walk(path):
print('Current path: ', dirpath)
print('Directories: ', dirnames)
for fname in filenames:
file.write(fname + os.linesep)
import time
from selenium import webdriver
from selenium.webdriver import ActionChains
driver = webdriver.Chrome()
driver.get('https://salsabeatmachine.org/')
move = ActionChains(driver)
# Ползунок BPM
thumb = driver.find_element_by_class_name('mat-slider-thumb')
# Открываем ползунок громкости пиано
driver.find_element_by_xpath('/html/body/bm-root/div[2]/mat-card[2]/div[4]/bm-instrument-tile/div/div[2]/button[2]/span/mat-icon').click()
# Сам ползунок громкости
piano_thumb = driver.find_element_by_xpath('/html/body/bm-root/div[2]/mat-card[2]/div[4]/bm-instrument-tile/mat-slider/div/div[3]/div[2]')
# Пускаем музыку
driver.find_element_by_class_name('mat-button').click()
time.sleep(2)
# Выключаем пианино и делаем такт быстрее
move.click_and_hold(thumb).move_by_offset(10, 0).release().perform()
move.click_and_hold(piano_thumb).move_by_offset(-200, 0).release().perform()
time.sleep(4)
# Ещё чуть быстрее
move.click_and_hold(thumb).move_by_offset(20, 0).release().perform()
time.sleep(4)
driver.quit()