def admin_snap_add(request): if not request.user.is_admin: return render(request, 'admin_login_invalid.html') else: if request.method == "POST": user = request.user form = SnapForm(request.POST, request.FILES) if form.is_valid(): snap = form.save(commit=False) snap.user = user snap.save() return HttpResponseRedirect('/custom123user/admin/snapview') else: form = SnapForm() return render(request, 'admin_snap_add.html', { 'form': form })
def admin_snap_settings(request, snap_id): if not request.user.is_admin: return render(request, 'admin_login_invalid.html') else: obj = Snap.objects.get(pk=snap_id) if request.user == obj.user: if request.method == 'POST': form = SnapForm(request.POST or None, request.FILES or None, instance=obj) if form.is_valid(): snap = form.save(commit=False) snap.save() return HttpResponseRedirect('/custom123user/admin/snapview') else: snap_id = snap_id form = SnapForm(instance=obj) return render(request, 'admin_snap_settings.html', {'form': form, 'snap_id': snap_id}) else: return render(request, 'wrong_user.html')