[Fixed]-Want to add data to a form, form is valid, but data not among cleaned_data

0👍

This isn’t the way to add data to a form submission. You should be adding it to the model instance, not the form, once that has been created in the form_valid method. You shouldn’t be overriding post at all.

class WikiCreate(CreateView):
    model = Wiki
    fields = ['article']

    def form_valid(self, form):
        related_model = self.kwargs.get('model')
        related_object_id = self.kwargs.get('pk')
        item = form.save(commit=False)
        item.related_model = related_model
        item.object_id = related_object_id
        item.save()
        return redirect(self.get_success_url())

1👍

This is because you only have the fields:


fields = ['article']

So there are no other fields on your form other than article. Try adding the other two fields to the fields array. If you want them to be there, but not visible you need to create a custom form and set them to have the hidden widget

Leave a comment