I'd like to use name__iexact
with get_or_create
to avoid duplication on user entered fields where possible.
My Provider model has a name field which I use in get_or_create
.
The lookup works fine but when creating an instance for the first time as in the p1/Timber example below (the name
Fails:
>>> p1, c1 = Provider.objects.get_or_create(name__iexact="Timber")
>>> p1, c1
(<Provider: >, True)
>>> p1.name
u''
Works as expected here:
>>> p2, c2 = Provider.objects.get_or_create(name="Cedar")
>>> p2.name, c2
('Cedar', True)
>>> p3, c3 = Provider.objects.get_or_create(name__iexact="Cedar")
>>> p3, c3
(<Provider: Cedar>, False)
>>> Provider.objects.get_or_create(name__iexact="cedar")
(<Provider: Cedar>, False)
Is __iexact
incompatible with the create portion of get_or_create
, is this expected behavior (and why), or have I run into a Django bug?