[Fixed]-DjangoRestFramework HTML views timeout

1đź‘Ť

As far as I understand, the problem is with the selectbox loaded with tons of items. The solution that is being used in django admins is to use “raw_id_fields” for the choicefields (or foreign keys) that have lots of items.

Unfortunately, DRF doesn’t support Raw ID fields for now. However, you can implement a similar approach by using autocomplete fields. Right now there isn’t built-in support, but you can use some external packages as described in DRF’s official documentation: http://www.django-rest-framework.org/topics/browsable-api/#autocomplete

0đź‘Ť

You should use select_related()/prefetch_related queryset methods to fetch the associated objects, which fill your selects. Post your models, serializer and a queryset so we can make a real example.

👤Alex Morozov

Leave a comment