Time out when requesting element from Admin

23 views
Skip to first unread message

Joakim Hove

unread,
Nov 14, 2015, 2:14:58 AM11/14/15
to Django users
[ I realize what I am trying to do might be a prime example of abusing the admin. The real answer to my question might very well be: 'sorry - the admin is just not made for that', and that is fine. The main reason I am asking this is to learn more myself - and most importantly to rule out other problems in my setup ]


Hello;

I have a model with ~200000 records and growing (is that "much"?). I can visit the /admin/app/model/ url in the Admin and get a listing of all the records/instances - but when I click on one of the actual instance - i.e. something /admin/app/model/12345/ the application times out (30 seconds on Heroku). The model in question is quite simple:

model A:
    foreignKey( B )
    foreignkey( C )
    float( )

model B
    foreignkey( D )
    foreignkey( D )
    foreignkey( E )

The relationship between A and B is 'nearly' one-to-one; i.e. there are roughly as many rows of A as there rows of B (The B model is currently not in the admin). For the other model C.D,E,.. the relationship is extremely 'many-to-few' - i.e. the database only contains a handful of C,D,E, instances. I was wondering if something like prefetching foreign keys??? brought the whole thing to its knees?


The site is actually mainly an API - and the model in question is also exposed through a Django Rest Framework (DRF) endpoint:



So - for the DRF configuration the situation is actually opposite; accessing the whole list times out (I have not done anything to configure pagination - so this might be OK?); whereas fetching one element is snappy. The admin site is password protected - but it only contains test-data and I would be happy provide login details if someone want's to take a look.

If someone can shed some light on this I would be very grateful.

Joakim


Joseph Wenninger

unread,
Nov 14, 2015, 5:20:07 AM11/14/15
to django...@googlegroups.com
I don't know about the rest part, but for admin I'd try to use raw_id_fields, that doesn't fetch the whole Unicode/str representation for all elements the foreign key could point to. Do you have some complex code in __unicode__ or __str__?

Raw Id documentation:
ModelAdmin.raw_id_fields

By default, Django’s admin uses a select-box interface (<select>) for fields that are ForeignKey. Sometimes you don’t want to incur the overhead of having to select all the related instances to display in the drop-down.

raw_id_fields is a list of fields you would like to change into an Input widget for either a ForeignKey orManyToManyField:


Best regards
Joseph




Von meinem iPhone gesendet
Am 14.11.2015 um 08:14 schrieb Joakim Hove <joaki...@gmail.com>:

knees?

Joakim Hove

unread,
Nov 15, 2015, 3:26:30 PM11/15/15
to Django users

By default, Django’s admin uses a select-box interface (<select>) for fields that are ForeignKey. Sometimes you don’t want to incur the overhead of having to select all the related instances to display in the drop-down.


Thanks a lot - that was what it was all about; Django tried to populate a <select> box O(10000) elements - fair enough that that timed out. I just removed the foreignkey in question from the AdminModel!

Joakim
Reply all
Reply to author
Forward
0 new messages