[Django]-Django modelform and passing extra parameter

4👍

You haven’t actually set an initial value for the ip form field meaning it’s empty. Try:

def __init__(self, *args, **kwargs):
    super(SignUpForm, self).__init__(*args, **kwargs)
    self.fields['ip'].initial = kwargs.pop('ip_addr', None)

The clean_ip method is for validation upon submission of the form and is only called after form.is_valid() is called. It should check that the value of the field is a valid ip

0👍

I don’t think you should use clean_ip here. You are not cleaning it anyhow. Either use initial in your view or override save method.

Leave a comment