On Mon, Jun 24, 2013 at 1:51 PM, Victor Rajewski <askvic...@gmail.com>wrote:

> Thanks Russ,
>
> This solves the problem from one end, however in my case the wrong end, as
> it would require the app I'm using (and presumably many
> other apps relying on the username field) to be re-written; besides which,
> USERNAME_FIELD is not present in the User model of django <= 1.4 so every
> query for a username would now need a try/except (at least for the first
> way you mention)
>

That's easy to fix:

UserModel.objects.get(**{getattr(UserModel, 'USERNAME_FIELD', 'username'):
desired_name})

And the second way doesn't work for get_object_or_404 or other convenience
> functions or more complex queries.
>

Well, sure; but get_object_or_404 isn't *that* complex; it's a try-catch
block. I'm not sure what other convenience functions you're referring to.
Django internally had to modify a bunch of convenience functions and
utility code (e.g., the model backend for auth) - yes, there was code that
needed to be written, but it wasn't *that* onerous.

As for complex queries -- the same trick I provided above works on more
complex queries; you just need to worry about putting in the
double-underscore joins and other query terms as necessary.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to