0

I am trying to use a ModelForm with only some of the model fields so that users can submit data, but I want the submissions to be emailed to me instead of saved in the database so I can check them over and add info for the rest of the fields before saving.

So to start off I think I need to modify save() so that the default for this modelform is commit=False.

I've looked at the docs and since all I want to do is change the default on this particular model to be commit=False I am wondering how to do that simple modification. If I could just do something like below and then email the instance data to myself.

class SK_form(ModelForm):
class Meta:
    model = Soup_Kitchen
    fields = ('name', 'address', 'phone_number', 'contact_person')

def save(self, commit=True):
    instance = super(SK_form, self).save(commit=False)
    return instance
LVNGD
  • 169
  • 3
  • 12

1 Answers1

0

I don't think this is what you really want to do. If you did it this way, the data won't be persisted anywhere. So when you receive the email, you'll have to cut and paste the data back into a Django form to recreate the instance before you can add your own data and save it.

It would be better to have a boolean field on the model - called for example complete - which records whether or not the data has been checked and completed, and defaults to False. You can then have a custom Manager which by default filters out all rows with complete=False.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895