from django.db.models import ExpressionWrapper, F
queryset.annotate(
distance=ExpressionWrapper(
expression=((1 - F("address__longitude")) * 2) + ((1 - F("address__latitude")) * 2),
output_field=models.FloatField,
),
) \
.order_by("distance")
celery --app=conf.celery.application worker -c 1 -Q localhost_0
celery --app=conf.celery.application worker -c 1 -Q localhost_1
celery --app=conf.celery.application worker -c 1 -Q localhost_2
celery --app=conf.celery.application worker -c 1 -Q localhost_3
update_quantity_task.apply_async(
kwargs={
'goods_id': related_product.goods_id,
},
queue='default_{}'.format(related_product.goods_id % 4),
)
class User(AbstractBaseUser, PermissionsMixin):
class Type(models.TextChoices):
default = 'default', 'Стандартный Пользователь'
vip = 'vip', 'Вип пользователь'
# forms.py
class BookmarksForm(forms.ModelForm):
def __init__(self, user, *args, **kwargs):
super(BookmarksForm, self).__init__(*args, **kwargs)
self.fields['folder'].queryset = Folders.objects.filter(user=user)
# views.py
form = BookmarksForm(request.POST, user=request.user.id)
# views.py
def bookmarks(request):
if request.method == 'POST' and 'create_folder' in request.POST: # форма создания папки
form = FolderForm(request.POST)
form.fields['folder'].queryset = Folders.objects.filter(user=request.user)
def bookmarks(request):
if request.method == 'POST':
folder_form = FolderForm(request.POST)
if folder_form.is_valid():
if 'create_folder' in request.POST:
pass
if 'create_bm' in request.POST:
pass
return redirect('bookmarks')
else:
form.add_error(None, 'Ошибка добавления папки')
else:
folder_form = FolderForm()
return render(request, 'mainapp/bookmarks.html', {
'title': 'закладки',
'folder_form': folder_form,
'bm_form': bookmarks_form,
'folders': folder,
'fl': fastlink
})
{% recursetree product.comments.all %}
{% with comment=node %}
<div class="comment-item_lvl-{{ comment.level|add:'1' }}">
{% include 'product/comment.html' %}
</div>
{% endwith %}
{% if not node.is_leaf_node and node.level <= 2 %}
{{ children }}
{% endif %}
{% endrecursetree %}
{% recursetree product.comments.all %}
<div class="comment-item_lvl-{{ node.level|add:'1' }}">
{% include 'product/comment.html' with comment=node %}
</div>
{% if not node.is_leaf_node and node.level <= 2 %}
{{ children }}
{% endif %}
{% endrecursetree %}
class MyModel(models.Model):
start = models.TimeField(null=True)
end = models.TimeField(null=True)
class MyForm(forms.Form):
start = forms. TimeField(required=True)
end = forms. TimeField(required=True)
def clean(self):
cleaned_data = super().clean()
start = cleaned_data.get("start")
end = cleaned_data.get("end")
check = MyModel.objects \
.filter(
Q(start__in=[start, end]) | (Q(end__in=[start, end])
).exists():
if check:
raise forms.ValidationError('error')
<script>
$(document).ready(function() {
$('.select2').each(function (idx, elem) {
$(elem).select2({
'language': 'ru',
});
});
}
</script>
{% load widget_tweaks %}
{% render_field form.spis class+="select2" data-minimum-results-for-search="Infinity" %}
self.portfolio.filter(name='123213')
os.path.join(BASE_DIR, 'templates')
BASE_DIR / 'templates'
{% load spurl %}
<a class="page-link" href="{% spurl query=request.GET set_query='page={{ p }}'%}">{{ p }}</a>