Skip to content

Commit

Permalink
update service creation
Browse files Browse the repository at this point in the history
  • Loading branch information
rasulkireev committed Oct 23, 2024
1 parent 07241f8 commit 499b09f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,18 @@ def get_success_url(self):

def post(self, request, *args, **kwargs):
self.object = self.get_object()
if "service_form" in request.POST:
if "name" in request.POST: # Check for a field from the service form
service_form = ServiceForm(request.POST)
if service_form.is_valid():
service = service_form.save(commit=False)
service.project = self.object
service.save()
messages.success(request, f"Service '{service.name}' has been successfully created!")
return redirect(self.get_success_url())
else:
# If the form is invalid, re-render the page with the form errors
context = self.get_context_data(object=self.object)
context["service_form"] = service_form
return self.render_to_response(context)
else:
return super().post(request, *args, **kwargs)

0 comments on commit 499b09f

Please sign in to comment.