OPTIONS fetches and shows all possible foreign keys in choices field · Issue #3751 · encode/django-rest-framework (original) (raw)
I have an object with foreign keys and when I load a OPTIONS
request for that object type, it shows me a truly insane JSON object with every possible value for the foreign key (there are millions!)
So, for example, I have this object:
class OpinionCluster(models.Model):
"""A class representing a cluster of court opinions."""
docket = models.ForeignKey(
Docket,
help_text="The docket that the opinion cluster is a part of",
related_name="clusters",
)
Which is serialized with:
class OpinionClusterSerializer(serializers.HyperlinkedModelSerializer): docket = serializers.HyperlinkedRelatedField( many=False, view_name='docket-detail', queryset=Docket.objects.all(), style={'base_template': 'input.html'}, )
When I load this with OPTIONS
, I get back something that contains:
"docket": {
"type": "field",
"required": true,
"read_only": false,
"label": "Docket",
"choices": [
{
"display_name": "4: United States v. Goodwin",
"value": "http://127.0.0.1:8000/api/rest/v3/dockets/4/"
},
{
"display_name": "5: Quality Cleaning Products v. SCA Tissue of North America",
"value": "http://127.0.0.1:8000/api/rest/v3/dockets/5/"
},
....millions more....
I know that there's a way to disable listing these items in the form of the HTML view, but in the OPTIONS request we need better default functionality than displaying millions of records.