category.category_set.all()
class Category(models.Model):
parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
category.children.all()
qs = Item.objects.all()
if not user.is_moderator:
qs = qs.filter(user=user)
student_struct = {}
summ = 0
summ = 0
for individual_mark in all_marks:
summ += individual_mark
sum(all_marks)
all_marks = student['marks']
student_struct = {}
student_struct['name'] = individual_name
student_struct['average'] = summ
student_struct = {
'name': student['Name'],
'average': sum(student['marks'])
}
students_data = [
{'name': 'Vasya', 'marks': [4, 5, 4, 5, 5]},
{'name': 'Petya', 'marks': [3, 5, 3, 4, 2, 2]},
{'name': 'Ivan', 'marks': [4, 5, 4, 4, 4, 4]},
{'name': 'Dima', 'marks': [4, 5, 4, 3, 3, 3]},
]
average_data = [{'name': student['name'], 'average': sum(student['marks'])} for student in students_data]
import shelve
data = shelve.open("quiz")
data["quiz1"] = {"theme" : None}
tmp = data["quiz1"]
tmp["theme"] = "Cinematograph"
data["quiz1"] = tmp
print(data["quiz1"]["theme"])
data.close()
Because of Python semantics, a shelf cannot know when a mutable persistent-dictionary entry is modified. By default modified objects are written only when assigned to the shelf (see Example). If the optional writeback parameter is set to True, all entries accessed are also cached in memory, and written back on sync() and close(); this can make it handier to mutate mutable entries in the persistent dictionary, but, if many entries are accessed, it can consume vast amounts of memory for the cache, and it can make the close operation very slow since all accessed entries are written back (there is no way to determine which accessed entries are mutable, nor which ones were actually mutated).
from poliv.settings import PUBLIC_URL
from django.conf import settings
settings.PUBLIC_URL
c.execute('UPDATE time SET Deleted = ? where rowid = 1', ['hello world'])
import eventlet
eventlet.monkey_patch()
import requests
urls = ['http://solutions.fas.gov.ru/search.json?action=index&'
'controller=documents&page=%s' % page for page in range(1, 29044)]
def fetch(url):
return requests.get(url)
pool = eventlet.GreenPool()
for response in pool.imap(fetch, urls):
# Клади ответ в ES
print('gotcha')