Hi all,
First of, I'm new to this list so please tell me if there's something that can be done better. It's the best way to learn for me ;)
Recently I've been doing some reworking of an old (think Django 1.1 or 1.2) webapp of mine into the latest and greatest of Django. In the process I modified some models, and thought that get_or_create would be perfect to replace boring try / except cases. Except that it didn't really work as planned. I tried to do a get_or_create(name__iexact=value, defaults={'slug': slugify(value)}). I expected this to be smart enough to know that it should fill the field name based on the name__iexact parameter. Apparently it isn't :) In this case you'd need to add a definition for name to the defaults dict to get the value into the newly created model. I'm not sure, but I personally think this shouldn't be that hard to fix. It's basically checking (and removing) known field lookups or simply everything after a double underscore, and using that as a field name. Or at least, that's my view on it.
The big question is:
1. Is this behavior that exotic that I'm the first one to notice, or did I do a wrong search on Google?
2. Would this indeed be as easy (or comparably easy) as I think?
3. Is this behavior we actually want in Django?
If the answer to 2 and 3 are yes, I'll look into giving it a try to making a patch for this myself.
Regards,
Patrick Bregman