django - Can I disable a field in the Rest Framework API browsing view -


i using django rest framework serialize model in have foreignkey.

models.py

class article(models.model):     author = models.foreignkey(author, related_name='articles')     ... other fields... 

serializers.py

class articleserializer(serializers.hyperlinkedmodelserializer):     class meta:         model = article 

i want rid of 'html form' @ bottom of browsable api view since list articles , retrieving them db takes ages (i have 100k articles, , each time html form displayed, server 100k queries).

i have read answer how disable admin-style browsable interface of django-rest-framework? , displaying view in json. however, html view , find way avoid html form available @ bottom.

i don't want remove field view (i need use it), remove database queries used populate form.

any idea ?

i answer own question. found in documentation solution problem. had use read_only attribute.

serializers.py

class articleserializer(serializers.hyperlinkedmodelserializer):     author = serializers.relatedfield(read_only=true)     class meta:         model = article         fields = ('author', ...other_fields) 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -