Code

Ticket #3851: ticket3851.diff

File ticket3851.diff, 630 bytes (added by Christopher Lenz <cmlenz@…>, 7 years ago)

Improved patch

Line 
1Index: django/db/models/manipulators.py
2===================================================================
3--- django/db/models/manipulators.py    (revision 260)
4+++ django/db/models/manipulators.py    (working copy)
5@@ -295,7 +295,10 @@
6             # doesn't have blank=True.
7             return
8         if isinstance(f.rel, ManyToOneRel):
9-            kwargs['%s__pk' % f.name] = field_val
10+            if field_val == '':
11+                kwargs['%s__isnull' % f.name] = True
12+            else:
13+                kwargs['%s__pk' % f.name] = field_val
14         else:
15             kwargs['%s__iexact' % f.name] = field_val
16     try: