Пытался ввести на (Телефоне) 127.0.0.1:8000 но - Can't establish a connection with site.
... runserver 0.0.0.0:8000
http://192.168.xxx.yyy:8000
если никакой файерволл дополнительно его не блокирует max_id = Products.objects.filter(draft=False).aggregate(max_id=Max("id"))['max_id']
random_products = []
if Products.objects.filter(draft=False).count() < 4:
raise Exception('Мало объектов для выборки')
while len(random_products) < 4:
pk = random.randint(1, max_id)
if pk in random_products:
continue
product = Products.objects.filter(draft=False, pk=pk).first()
if product:
random_products.append(product)
my_files = os.listdir('<путь до папочки>')
context['links'] = [f'/некий урл/{my_file}' for my_file in my_files]
location /некий урл
{
alias /путь/до/папки;
}
YEAR_HOLIDAYS = 'HOLIDAYS:{year}'
...
@classmethod
def is_work_day(cls, date):
if date.weekday() in [5,6]:
return False
holidays = cache.get(YEAR_HOLIDAYS.format(year=date.year))
if not holidays:
holidays = cls.objects.filter(year=date.year).values_list('date', flat=True)
cache.set(YEAR_HOLIDAYS.format(year=date.year), holidays)
if date in holidays:
return False
return True
UPD: как это влияет на БД и в чём выгода использования конкретных типов полей?
def slugify(value, allow_unicode=False):
"""
Convert to ASCII if 'allow_unicode' is False. Convert spaces to hyphens.
Remove characters that aren't alphanumerics, underscores, or hyphens.
Convert to lowercase. Also strip leading and trailing whitespace.
"""
In [1]: unicodedata.normalize('NFKD', 'привет world')
Out[1]: 'привет world'
In [2]: 'привет world'.encode('ascii', 'ignore').decode('ascii')
Out[2]: ' world'
In [3]: my_string = 'привет world'.translate(
str.maketrans(
"абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ",
"abvgdeejzijklmnoprstufhzcss_y_euaABVGDEEJZIJKLMNOPRSTUFHZCSS_
...: Y_EUA"
))
In [4]: slugify(my_string)
Out[4]: 'privet-world'
class Arena(models.Model):
exp_time = models.DateTimeField(...
win_count = models.PositiveIntegerField(default=0, ...
...
class ArenaUser(models.Model):
arena = models.ForeignKey(Arena,...
user = models.ForeignKey(User,...
...
class Arena(models.Model):
exp_time = models.DateTimeField(...
win_count = models.PositiveIntegerField(default=0, ...
users = models.ManyToManyField(User,...
...