Purpose of widget parameter in Tutorial 1

29 views
Skip to first unread message

Lucas Simon

unread,
May 14, 2013, 12:24:32 PM5/14/13
to django-res...@googlegroups.com
When defining the snippet serializer in the first tutorial, it is not explained as to why the widget parameter is added for the code variable. What is the purpose of doing this?

class SnippetSerializer(serializers.Serializer):
    pk = serializers.Field()  # Note: `Field` is an untyped read-only field.
    title = serializers.CharField(required=False,
                                  max_length=100)
    code = serializers.CharField(widget=widgets.Textarea,
                                 max_length=100000)

Matthieu Neamar

unread,
May 14, 2013, 12:26:15 PM5/14/13
to django-res...@googlegroups.com
When using the browsable API (e.g. when using Firefox instead of curl / wget), you'll see a form at the end of the page to create a new snippet.

By default, the widget for a CharField is a <input>. By specifying the widget, we get a nice textarea to enter the snippet's code.


--
You received this message because you are subscribed to the Google Groups "django-rest-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Lucas Simon

unread,
May 14, 2013, 12:33:20 PM5/14/13
to django-res...@googlegroups.com
Great! Is there any way to edit the docs to add this information? I would be more than happy to edit them.

Matthieu Neamar

unread,
May 14, 2013, 12:36:37 PM5/14/13
to django-res...@googlegroups.com
Yes there is!
You can fork https://github.com/tomchristie/rest-framework-tutorial and make a pull request to Tom.

Note however the documentation (not the tutorial) explains the purpose ot the widget parameter: http://django-rest-framework.org/api-guide/fields.html#widget


Lucas Simon

unread,
May 14, 2013, 12:46:01 PM5/14/13
to django-res...@googlegroups.com
Thank you, I will do that. It's good that the standard documentation has that; but, the tutorial should include all details explicitly, not doing so is one of my largest pet peeves. 
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages