def neo_create(request): if request.method == 'POST': form = NeoForm(request.POST) if form.is_valid(): f = form.save(commit=False) f.user = request.user form.save() return redirect('/dashboard/') else: form = NeoForm() return render(request, 'neo_edit_or_create.html', {'form': form})
def neo_edit(request, u_id): try: obj = Neo.objects.get_or_create(id=u_id, user=request.user) if request.method == 'POST': form = NeoForm(request.POST, instance=obj) if form.is_valid(): f = form.save(commit=False) f.user = request.user form.save() return redirect('/dashboard/') else: form = NeoForm() return render(request, 'neo_edit_or_create.html', {'form': form}) except Neo.DoesNotExist: return redirect('/dashboard/')
def neo_edit(request, no): me = UserProfile.objects.get(user=request.user) try: obj = Neo.objects.get_or_create(no=no, user=request.user) if request.method == 'POST': form = NeoForm(request.POST, instance=obj) if form.is_valid(): f = form.save(commit=False) f.user = request.user form.save() return redirect('/dashboard/') else: form = NeoForm() return render(request, 'neo_edit_or_create.html', {'form': form, 'me': me}) except Neo.DoesNotExist: return redirect('/dashboard/')
def neo_create(request): if request.method == 'POST': form = NeoForm(request.POST) if form.is_valid(): f = form.save(commit=False) f.user = request.user curdate = datetime.now() latest_no = Neo.objects.filter(created__year=curdate.strftime("%Y"), created__month=curdate.strftime("%m"), created__day=curdate.strftime("%d")).count() new_no = latest_no + 1 tmpid = "%03d" % ( new_no ) f.no = str(curdate.strftime("%Y%m%d")) + tmpid form.save() return redirect('/dashboard/') else: form = NeoForm() return render(request, 'neo_edit_or_create.html', {'form': form})
def neo_create(request): if request.method == 'POST': form = NeoForm(request.POST) if form.is_valid(): f = form.save(commit=False) f.user = request.user curdate = datetime.now() latest_no = Neo.objects.filter( created__year=curdate.strftime("%Y"), created__month=curdate.strftime("%m"), created__day=curdate.strftime("%d")).count() new_no = latest_no + 1 tmpid = "%03d" % (new_no) f.no = str(curdate.strftime("%Y%m%d")) + tmpid form.save() return redirect('/dashboard/') else: form = NeoForm() return render(request, 'neo_edit_or_create.html', {'form': form})
def neo_edit(request, no): me = UserProfile.objects.get(user=request.user) try: obj = Neo.objects.get_or_create(no=no, user=request.user) if request.method == 'POST': form = NeoForm(request.POST, instance=obj) if form.is_valid(): f = form.save(commit=False) f.user = request.user form.save() return redirect('/dashboard/') else: form = NeoForm() return render(request, 'neo_edit_or_create.html', { 'form': form, 'me': me }) except Neo.DoesNotExist: return redirect('/dashboard/')