Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Forms: Writing data to database

Tags:

forms

django

This doc explains how to gather form data for sending as mail. But, how can it be made to write the data to the database and made available in the admin interface?

like image 254
nixnotwin Avatar asked Sep 12 '26 23:09

nixnotwin


1 Answers

The simplest method would be to use ModelForm to create a form based on your model. Calling form.save() on that form will automatically save your data to the database.

If you created your form manually, you will have to manually populate a model instance and then call .save() on your model instance.

like image 148
Shawn Chin Avatar answered Sep 14 '26 14:09

Shawn Chin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!