Django's admin default widget for foreign keys is a select. If you try to
populate a select elements with 20,000 options, your page take at least a
few seconds to load. Probably a minute or two, if it load at all.

By configuring your model admin to display the foreign key as a
raw_id_fields, you get an simple input instead of a select. It's less nice
to use but it's much faster.

On Thu, Jan 17, 2019, 13:48 shiva kumar <kannamshivakumar...@gmail.com
wrote:

> actually i am new to django i am not able to understand the problem which
> ur dealing with?
>
> On Thu, Jan 17, 2019 at 3:33 AM Santiago Basulto <
> santiago.basu...@gmail.com> wrote:
>
>> Hey folks, I was about to submit a ticket but i thought it might be
>> better to ask everybody for opinions on the matter first. I am running a
>> couple of medium (not even large) Django websites (around +20K users) and
>> we rely on the admin heavily. We have multiple models pointing to Users (or
>> other derived models) and every time we create a new model, we MUST
>> remember to include User in `raw_id_fields` for that model. If we forget to
>> do so, the whole testing site crashes when the whole `SELECT * FROM User`
>> query is run.
>>
>> To add to the problem, some derived models (for example Customer) include
>> in their `__str__` both the User + something else. Think about the model
>> Customer in this way:
>>
>> class Customer(models.Model):
>>     user = models.ForeignKey(User)
>>     plan = models.ForeignKey(Plan)
>>
>>
>>     def __str__(self):
>>         return f"{self.user} - {self.plan}"
>>
>>
>> (Not a real example, but to make the point)
>>
>> Imagine any other model with an FK to Customer, an `Inquiry`, for
>> example. If you open the `Inquiry` add/change page on the admin, the whole
>> thing will blow up.
>>
>> I know the related select field is an amazing feature, and looks slick on
>> the admin when starting a new Django projects (specially for beginners),
>> but it just doesn't scale for large websites.
>>
>> *My proposal*
>>
>> I think just a project-wide setting `settings.ADMIN_DEFAULT_FK_WIDGET =
>> [raw|select]` would work and help us (running a medium/large site) a lot.
>>
>> What do you think?
>>
>> Thanks for all the support, this community rocks 🤘!
>>
>> PS: I can create a ticket if that's a better medium of discussion, just
>> let me know?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django developers (Contributions to Django itself)" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-developers+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-developers@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-developers.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-developers/5dae8b31-356c-45f3-b707-83b5ef33f396%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-developers/5dae8b31-356c-45f3-b707-83b5ef33f396%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 developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/CAMsYeuFUNE3W8Cc2RGwn7L-LZ%2BhrNy9NPxiYVx_ZH7H4kUzR0Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-developers/CAMsYeuFUNE3W8Cc2RGwn7L-LZ%2BhrNy9NPxiYVx_ZH7H4kUzR0Q%40mail.gmail.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 developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAEuG%2BTaajgmBC37fjiHfSXJNOFvTmU%2B29Cz-G-zbLMsiuN3yyQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to