method_decorator(csrf_protect)
def form_valid(self, form):
resp = super(DoneAdd, self).form_valid(form)
# после вызова суперметода в self.object находится созданный по форме объект
user = self.request.user
model = Service.objects.all()
if user.is_authenticated:
user.loads_services.add(model.get(pk=self.object.pk))
user.save()
return resp
class ServiceCreateView(CreateView):
model = Service
template_name = 'elitemservice/main.html'
def form_valid(self, form):
resp = super(ServiceCreateView, self).form_valid(form)
# после вызова суперметода в self.object находится созданный по форме объект
user = self.request.user
if user.is_authenticated:
user.loads_services.create(
pk=self.object.pk,
name_service=self.object.name_service,
about_service=self.object.about_service,
file_service=self.object.file_service,
)
user.save()
return resp
django.core.exceptions.ImproperlyConfigured: Using ModelFormMixin (base class of ServiceCreateView) without the 'fields' attribute is prohibited.
$.ajax({
type: "POST",
url: "{% url 'doneAddService' %}",
data: {
'form': $('#addServiceForm').serialize()
},
success: function () {
window.location = '/'
}
})
user.loads_services.create(
pk=to_pk,
name_service=name_service,
about_service=about_service,
file_service=file_service
)