Я хочу сохранить данные формы, отправленные пользователем в формате JSON в базу данных mon go. Моя форма отправляется при отправке формы, но я не мог понять, как сохранить отправленную форму в формате MongoDB JSON.
forms.py
class appointment(forms.Form):
name = forms.CharField(max_length=100, label="Name")
gender = forms.ChoiceField(widget=forms.RadioSelect, choices=G_CHOICES)
age = forms.CharField()
phone_number = forms.CharField()
email_id = forms.EmailField(max_length=250)
country = CountryField().formfield()
department = forms.ChoiceField(choices=D_CHOICES)
reports = forms.ImageField()
views.py
def appointmentform(request):
if request.method == "POST":
form = appointment(request.POST, request.FILES)
if form.is_valid():
form.save()
print(form.cleaned_data)
print(form.cleaned_data.get("name"))
print(form.cleaned_data.get("gender"))
print(form.cleaned_data.get("age"))
print(form.cleaned_data.get("phone_number"))
print(form.cleaned_data.get("country"))
print(form.cleaned_data.get("department"))
print(form.cleaned_data.get("reports"))
form = appointment
return render(request, "appointment.html", {"form": form})