tags:

views:

7

answers:

0

I monkey-patched User model with the following two lines:

User._meta.get_field_by_name('email')[0]._unique = True     
User._meta.get_field_by_name('email')[0].max_length = 125   

-- and noticed, that models loaded after those two lines are executed, are not reachable from User.objects.filter(). For example, I have UserProfile model, pointing to User, and when the mentioned lines precede UserProfile class definition, User.objects.filter(userprofile__id=1) results in:

 FieldError: Cannot resolve keyword 'userprofile' into field. Choices are: (...)

But when I moved them to the end of the source file containing UserProfile class, everything started to work as expected. I confirmed this also for other models pointing to User model.

Have some else encountered this?