Answer the question
In order to leave comments, you need to log in
How to shorten django code?
Good afternoon! I'm a newbie and can't find options.
The front is made on the site, the client selects the activity and the choice falls into the form wrapper. There is no way to place django forms in the wrapper. I save by input name. How can you optimize your code
class MasterProfile(generic.View):
def post(self, request):
razdel1 = HairCut.objects.all()
uslugi_haircut = HaircutUslugi()
razdel2 = SpaCentre.objects.all()
ctx = {
'razdel1': razdel1,
'uslugi_haircut': uslugi_haircut,
'razdel2': razdel2
}
if request.method == "POST":
data = HairCut()
data.deyatelnost1 = request.POST.get('deyatelnost1')
data.save()
data = HaircutUslugi()
data.usluga1 = request.POST.get('usluga1')
data.save()
data = SpaCentre()
data.deyatelnost2 = request.POST.get('deyatelnost2')
data.save()
data = Cosmetologia()
data.deyatelnost3 = request.POST.get('deyatelnost3')
data.save()
data = Makeup()
data.deyatelnost4 = request.POST.get('deyatelnost4')
data.save()
data = Nails()
data.deyatelnost5 = request.POST.get('deyatelnost5')
data.save()
data = Tatoo()
data.deyatelnost6 = request.POST.get('deyatelnost6')
data.save()
data = Massage()
data.deyatelnost7 = request.POST.get('deyatelnost7')
data.save()
data = Depilation()
data.deyatelnost8 = request.POST.get('deyatelnost8')
data.save()
return render(request, "masterregistration/masterprofilestart.html", ctx)
def get(self, request,):
razdel1 = HairCut.objects.all()
uslugi_haircut = HaircutUslugi()
razdel2 = SpaCentre.objects.all()
ctx = {
'razdel1': razdel1,
'uslugi_haircut': uslugi_haircut,
'razdel2': razdel2
}
return render(request, "masterregistration/masterprofilestart.html", ctx)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question