Kim Majali wrote on 06/06/2022
from django.db.models import F
company = Company.objects.filter(
num_employees__gt=F('num_chairs')).annotate(
chairs_needed=F('num_employees') - F('num_chairs')).first()
Read moreKim Majali wrote on 03/06/2022
from django.shortcuts import redirect
return redirect('glossaries')
Read moreKim Majali wrote on 03/06/2022
for data in request.POST:
if "sub_service_" in data:
sub_service_id = int(data.replace("sub_service_", ""))
CompanySubService.objects.select_for_update().filter(id=sub_service_id).update(delivery_per_hour = request.POST[data])
if request.POST.get("form_type") == 'update_sub_services_delivery':
try:
for data in request.POST:
if "sub_service_" in data:
sub_service_id = int(data.replace("sub_service_", ""))
CompanySubService.objects.select_for_update().filter(id=sub_service_id).update(delivery_per_hour = request.POST[data])
messages.success(request, "Sub services delivery info has been updated." )
except Exception as e:
print("Exception update_sub_services_delivery ==========================")
messages.error(request, "Error. Something went wrong.")
print(e)
print("End of Exception ==========================")
return render(request, template_name, context)
Read moreKim Majali wrote on 03/06/2022
record.full_timer = request.POST.get('full_timer', False)
if record.full_timer == 'on':
record.full_timer = True
record.save(update_fields=['full_timer'])
print('record updated')
Read moreKim Majali wrote on 03/06/2022
from django.conf.urls import url
from boards import views
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^about/$', views.about, name='about'),
]
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^about/$', views.about, name='about'),
url(r'^about/company/$', views.about_company, name='about_company'),
]
from django.conf.urls import url
from boards import views
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^(?P[\w.@+-]+)/$', views.user_profile, name='user_profile'),
]
url(r'^users/(?P\d+)/$', 'viewname', name='urlname')
def viewname(request, user_id):
user = User.objects.get(id=user_id)
class SampleView(TemplateView):
def get_context_data(self, **kwargs):
user = User.objects.get(id=kwargs['user_id'])
url(r'^products/$', 'viewname', name='urlname')
def viewname(request):
price_lte = request.GET['price_lte']
url(r'^register/$', 'register', name='urlname')
def register(request):
form = RegisterForm()
if request.method == "POST":
form = RegisterForm(request.POST) #if no files
if form.is_valid():
#do something if form is valid
context = {
'form': form
}
return render(request, "template.html", context)
path('drinks//',...),
re_path(r'^drinks/(?P\D+)/',...),
path('stores//',...),
re_path(r'^stores/(?P\d+)/',...),
Read more