Currently the form instance is being saved but the user who filled out the information isn't being saved when I save this form. I am wondering how to grab the user and have it be added to the creation of the new form object.
class ObjectListView(LoginRequiredMixin, FormMixin, ListView): model = Object template_name = 'ui/home.html' context_object_name = 'objects' form_class = OrderForm def post(self, request, *args, **kwargs): form = self.get_form() if form.is_valid(): form.save() order_type = form.cleaned_data.get('order_type') price = form.cleaned_data.get('price') **user = request.user** messages.success(request, f'Your order has been placed.') return redirect('account') https://stackoverflow.com/questions/65526094/how-to-save-user-when-saving-a-form-using-post-within-class-based-views-in-djang January 01, 2021 at 06:49AM
没有评论:
发表评论