Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DRF APIView - How can I add help text to auto generated form?

I am working with Django Rest Framework and using APIView and serializer form to add new data. I want to add some help text to the form as tooltip. Since the form is auto generated, I need some help on how can I add this to the form. I am using ModelSerializer.

This is how my serializer looks like

class MySerializer(serializers.ModelSerializer):
    class Meta:
        Model = MyModel
        fields = ('id','name', ...)

My form fields should have help texts. How can I add them? Thanks!

like image 894
Al Amin Avatar asked Oct 16 '25 04:10

Al Amin


1 Answers

Specify help_text as additional keyword argument (see documentation) instead declaring a serializer field specifying all options that are already in the model field (unique, null, max_length etc.)

class MySerializer(serializers.ModelSerializer):
    class Meta:
        model = MyModel
        fields = ('id','name', ...)
        extra_kwargs = {
            'name': {
                'help_text': 'You help text here...'
            }
        }
like image 115
Lucas Weyne Avatar answered Oct 18 '25 17:10

Lucas Weyne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!