import json
json_string = """[
{
"uid_1c": "c1f5e839-0c1d-11ed-aa44-ac1f6bd30991",
"number": "1",
"amount": 19
},
{
"uid_1c": "c1f5e839-0c1d-11ed-aa44-ac1f6bd30991",
"number": "2",
"amount": 10
},
{
"uid_1c": "7421a94a-4327-11ed-aa45-ac1f6bd30990",
"number": "3",
"amount": 200
}
]"""
json_object = json.loads(json_string)
# делаем базовый словарь на каждый уникальный uid
base_dict_elem = {el.get('uid_1c'): {'uid_1c': el.get('uid_1c'), 'number': 0, 'amount': 0} for el in json_object}
# итерируемся по списку словарей(json) для заполнения основного словаря
for el in json_object:
uid = el.get('uid_1c')
amount = el.get('amount')
base_dict_elem[uid]['amount'] += amount
# формируем список словарей с уникальными uid и статистикой
result = []
counter = 1
for k, v in base_dict_elem.items():
v['number'] = counter
result.append(v)
counter += 1
print(result)
def unique_with_sum(arr, id_key, sum_key):
unique = {}
for n in arr:
unique.setdefault(n[id_key], { **n, sum_key: 0 })[sum_key] += n[sum_key]
return [*unique.values()]
result = unique_with_sum(arr, 'uid_1c', 'amount')
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, DELETE
from django.contrib.contenttypes.models import ContentType
LogEntry.objects.log_action(
user_id=request.user.id,
content_type_id=ContentType.objects.get_for_model(some_model).pk,
object_id=object.id,
object_repr=str(object),
action_flag=ADDITION)
def make_upload_path(instance, filename):
return u'instructions/%s' % filename
let images = document.body.querySelectorAll(`img`);
document.addEventListener(`keydown`, event => {
let index = +String.fromCharCode(event.which) - 1;
if (index < 5) {
images[index].style.display = `block`;
}
}, false);
&tpl=`@CODE:
<div class="news-item">
<div class="date">[[+дата-публикации]]</div>
<div class="news-title">[[+pagetitle]]</div>
<div class="news-intro">[[+introtext]]</div>
<a href="[[~[[+id]]]]">подробнее</a>
</div>
`
fucnction lockOrderUrl($url,$lockUrl = '#'){
$hour = date('H');
$lockLink = ($hour >=21 || $hour <=10 );
return $lockLink ? $lockUrl : $url;
}
<a href="<?=lockOrderUrl('Тут путь к заказу', 'линк куда нужно перекидывать можно зашить в функцию если он не меняется'); ?>
mapping = {
'manufacturer': ('manufacturer', None),
'kind': ('kind', None),
'min_mem': ('size__gte', int),
'max_mem': ('size_lte', int),
'interface': ('interface', None),
'ff': ('ff', None),
'min_price': ('price__gte', int),
'max_price': ('price__lte', int)
}
list_of_drives = Drive.objects.all()
for k, v in mapping.items(): # iteritems() если Python2
if k in request.GET:
value = request.GET[k]
if callable(v[1]):
value = v[1](value)
list_of_drives = list_of_drives.filter(**{v[0]: value})
map.on('click', function() {
if (!map.scrollWheelZoom.enabled()) {
map.scrollWheelZoom.enable();
}
});
map.on('mouseout', function() {
map.scrollWheelZoom.disable();
});