The point of using a OneToOne relation to create a 'profile' is that the
profile is meant to contain information that is only accessed on an
individual basis (such as displaying a single users' address, etc.), and
generally not involved on bulk queries as you describe.

If your __str__() method in your primary user model accesses an attribute
via a foreign key lookup (ie OneToOne), then you'll get the behavior you
are describing. You want the data that you'll need all or most of the time
in the primary model to avoid that situation. In this case, I would suggest
you look at the attribute you're referencing and move it directly into the
primary user model.

I'm a little worried about what you mean by 'monkey patching'. Did you just
override the __str__() methods on your primary model?

-James
On May 18, 2015 3:58 PM, "Ilya Kazakevich" <kazakevichi...@gmail.com> wrote:

> Hello,
>
> I want to add just a one field to my model, and this field participates in
> user representation ( I use monkeypatch to change __str__).
>
> Django manual tells me to create profile with one-to-one relation in this
> case. Well, it may work. But if I have <select> with 250 users, I face 250
> "SELECT" queries to my db (N+1). I need to tell "UserManager" somehow to
> use "select_related". But how can I do that with out of new ugly
> monkeypatching?
> Does there is an official (recommended) way to do that? If no, how  can I
> use one-to-one user profile if I have "list of users" webpage with out of
> N+1? How to add one field to user model not extending it?
>
> I am really unhappy with idea of using custom user model.
> Thanks.
>
>
>  --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5bdd87b6-9cc6-4490-8b85-d25ecfe8ed16%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5bdd87b6-9cc6-4490-8b85-d25ecfe8ed16%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVa3Fqte4584jOfT99vQE4CfprbyrBnwEL%2BwuxapGRcew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to