django forms template


form = AddRecordForm(request.POST or None, request.FILES, instance=current_record)

if I add request.FILES,
image
data dont come here test t and test t not show in the input field

Please show your AddRecordForm and the complete view where you’re trying to use it.

1 Like

thanks I found solution

before


def update_record(request, pk):
	# Check if the user is authenticated
	if request.user.is_authenticated:
		# Check if the user has the permission to update records
		if request.user.has_perm('website.update_record'):
			# Get the record or return 404 if not found
			current_record = get_object_or_404(Record, id=pk)

			# Handle POST request with file uploads (images, etc.)
			form = AddRecordForm(request.POST or None, request.FILES or None, instance=current_record)

			if form.is_valid():
				form.save()
				messages.success(request, "Ma'lumotlar o'zgartirildi!")
				return redirect('records')  # Redirect to the records list or another relevant view
			else:
				messages.error(request, "Formada xatolik bor, iltimos qaytadan tekshiring!")

			return render(request, 'update_record.html', {'form': form, 'record': current_record})

		else:
			# If user doesn't have permission
			messages.error(request, "Sizda bu ma'lumotni yangilash huquqi yo'q!")
			return redirect('index')

	else:
		# If user is not authenticated
		messages.error(request, "Siz ro'yhatdan o'tgan bo'lishingiz lozim!")
		return redirect('index')

here is solution I write ‘form’: form,


def update_record(request, pk):
	# Check if the user is authenticated
	if request.user.is_authenticated:
		# Check if the user has the permission to update records
		if request.user.has_perm('website.update_record'):
			# Get the record or return 404 if not found
			current_record = get_object_or_404(Record, id=pk)

			# Handle POST request with file uploads (images, etc.)
			form = AddRecordForm(request.POST or None, request.FILES or None, instance=current_record)

			if form.is_valid():
				form.save()
				messages.success(request, "Ma'lumotlar o'zgartirildi!")
				return redirect('records')  # Redirect to the records list or another relevant view
			else:
				messages.error(request, "Formada xatolik bor, iltimos qaytadan tekshiring!")

			return render(request, 'update_record.html', {'form': form, 'record': current_record})

		else:
			# If user doesn't have permission
			messages.error(request, "Sizda bu ma'lumotni yangilash huquqi yo'q!")
			return redirect('index')

	else:
		# If user is not authenticated
		messages.error(request, "Siz ro'yhatdan o'tgan bo'lishingiz lozim!")
		return redirect('index')