Paste the following form into the __init__ form
for field in form.fields: form.fields[field].required = False
For example:
class MySexyForm(Form): def __init__(self, *args, **kwargs): super(MySexyForm, self).__init__(*args, **kwargs) for field in self.fields: self.fields[field].required = False
Then call:
form = MySexyForm(...) form.save()
However, you need to make sure that your clean() method can handle any missing attributes, conditionally checking to see if they exist in cleaned_data. For example, if another form field check is based on customer_id , but your incomplete form did not specify one, then customer_id will not be in cleaned_data.
If this is for the model form, you can check if the value was in cleaned_data , and drop it to instance.field if it is missing, for example;
def clean(self): inst = self.instance customer_id_new = self.cleaned_data.get('customer_id', None) customer_id_old = getattr(self.instance, 'customer_id') if inst else None customer_id = customer_id_new if customer_id_new else customer_id_old
Remember that the value of the new value will almost certainly not be in the same format as the old value, for example customer_id can actually be RelatedField on the model instance, and pk int in the form data. Again, you will need to handle these type differences within your pure.
This is one area where Django Forms is lacking sadly.
sleepycal
source share