django form without any fields

3.7k Views Asked by At

What I am trying to achieve is:

  • User fills in form
  • User has the option to see a Preview if the content he just provided
  • User can accept the Preview or work on the form

My Problem is when the User clicks on Preview I can pass a Modelform with the data and show it to him. But since there are no fields in the he can just click on Accept to publish his Content. I need a form which is like a Deny/Accept Dialog but still related to the Model because i have to make changes before saving it to the database.

I tried to exclude all fields and also fields=None

I read this but the solution looks a little hacky. FormPreview is not what i want because it is a too different approach.

Is there any way to create a form that consists of just a button? I am also able to pass the data from view to view, so in worst case it hasnt to be a ModelForm.

1

There are 1 best solutions below

0
On

I found a solution which fits my needs: Just take any_field and make it a hidden field:

from django.forms import HiddenInput

class MyModelForm(ModelForm):
    class Meta:
        model = MyModel
        widgets = {'any_field': HiddenInput(),}

Dont forget to exclude all the other fields.