-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Description
By default, any ForeignKey field is rendered on the autogenerated "HTML Form" page as a select widget showing all records in the database.
Usually, this is fine, but for databases with large tables containing many thousands of records, this causes this page rendering to take a long time, or possibly even timeout, as the page tries to render all the tags.
Django's admin handles this problem with a feature called "raw_id_fields" which allows you to specify the ForeignKey fields which should just be rendered as a simple CharField containing the record ID, greatly speeding up rendering performance.
Does DRF have a similar feature? I can find nothing in the docs.
A similar question has been asked on Stackoverflow, and the suggested solution is to explicitly define your "raw id field" as a class attribute in your serializers.ModelSerializer, but this seems clunky and difficult to make dynamic.