update form data saved

This commit is contained in:
Yogesh Ojha
2020-05-10 23:28:12 +05:30
parent 50643f111d
commit a443a0e442
2 changed files with 13 additions and 3 deletions
+4 -1
View File
@@ -26,7 +26,10 @@ class RawDomainForm(forms.Form):
"id": "domainDescription",
}
))
class UpdateDomainForm(forms.Form):
class UpdateDomainForm(forms.ModelForm):
class Meta:
model = Domain
fields = ['domain_name', 'domain_description']
domain_name = forms.CharField(
validators=[validate_domain],
required=True,
+9 -2
View File
@@ -36,8 +36,15 @@ def delete_domain(request, id):
return http.JsonResponse(responseData)
def update_target_form(request, id):
domain = Domain.objects.get(pk=id)
domain = get_object_or_404(Domain, id=id)
form = UpdateDomainForm()
form.set_value(domain.domain_name, domain.domain_description)
if request.method == "POST":
form = UpdateDomainForm(request.POST, instance=domain)
if form.is_valid():
form.save()
messages.add_message(request, messages.INFO, 'Domain edited successfully')
return http.HttpResponseRedirect(reverse('list_target'))
else:
form.set_value(domain.domain_name, domain.domain_description)
context = {'list_target_li': 'active', 'target_data_active': 'true', "domain":domain, "form":form}
return render(request, 'target/update.html', context)