diff --git a/django/forms/models.py b/django/forms/models.py
index 6024a1c..590e74e 100644
a
|
b
|
class BaseModelForm(BaseForm):
|
246 | 246 | lookup_kwargs = {} |
247 | 247 | for field_name in unique_check: |
248 | 248 | lookup_kwargs[field_name] = self.cleaned_data[field_name] |
249 | | |
| 249 | # If the field can be null, we need to exclude null values from |
| 250 | # the query, since in SQL NULL != NULL |
| 251 | if self.instance._meta.get_field_by_name(field_name)[0].null: |
| 252 | lookup_kwargs["%s__isnull" % field_name] = False |
250 | 253 | qs = self.instance.__class__._default_manager.filter(**lookup_kwargs) |
251 | 254 | |
252 | 255 | # Exclude the current object from the query if we are editing an |
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
index e3821de..58e9a4d 100644
a
|
b
|
class Inventory(models.Model):
|
144 | 144 | |
145 | 145 | def __unicode__(self): |
146 | 146 | return self.name |
| 147 | |
| 148 | class Patient(models.Model): |
| 149 | name = models.CharField(max_length=25, blank=True, null=True) |
147 | 150 | |
148 | 151 | __test__ = {'API_TESTS': """ |
149 | 152 | >>> from django import forms |
… |
… |
ValidationError: [u'Select a valid choice. z is not one of the available choices
|
1251 | 1254 | >>> core = form.save() |
1252 | 1255 | >>> core.parent |
1253 | 1256 | <Inventory: Pear> |
| 1257 | |
| 1258 | >>> class PatientForm(ModelForm): |
| 1259 | ... class Meta: |
| 1260 | ... model = Patient |
| 1261 | >>> form = PatientForm({}) |
| 1262 | >>> form.save() |
| 1263 | <Patient: Patient object> |
| 1264 | >>> form = PatientForm({}) |
| 1265 | >>> form.save() |
| 1266 | <Patient: Patient object> |
1254 | 1267 | """} |