user2959896
user2959896

Reputation:

Can I use Forms or do you strongly recommend ModelForm instead?

I find using the regular Forms API easier than ModelForm but I dont find any methods for saving the data to the database (I have read the Working with Forms, the Forms API, searched google etc). How are you suppose to save the form data to the database, do you have to instantiate a model you have, then populate the fields with the form data and then use the model objects' save method ? If thats the case then maybe ModelForm would be a lot easier in the long run because saving to the database would be a lot less coding...

I dont always want to save data to all the fields in the database, only some and that seems to create a problem when using ModelForm, or is this where the exclude keyword comes in ? The ModelForm API seems a little too complicated then it should be just to save data from a form which is why I've used the regular Forms API where I can create what I need easy but saving the data seems to be a hassle, what are you pointers on this, can I use the regular Forms API or do you strongly recommned me to take another read through ModelForm and use that? I think it would be easier to use the regular Forms and I don't mind a litte more coding but if its a lot more than I might check out the ModelForm after all

Upvotes: 0

Views: 137

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599788

I can't imagine what you're finding complicated about "the ModelForm API". It's exactly the same as the basic Form API, with the addition of the inner Meta class to automatically create fields from the model, and the save method to save to a model.

Of course the basic Form doesn't have any way of saving directly to a model. That's exactly what the ModelForm is for. A non-model form doesn't know anything about any models, so it can't save to them.

Upvotes: 1

Related Questions