Add a method to return the string value used in
choices of a
An example. An address model has a foreign key relationship with a country model.
A model serializer is declared using the address model.
In the template a HTML select control is rendered for the user (customer) to choose a country for their address. This is achieved by using the country field's
The rendered HTML is.
And the user (customer) sees this in the browser.
Continuing on the example. A different user (staff) of the system may also be editing instances of the same country model but would benefit from additional information than that of other users (customers), in this case the
With the use of a method that subclasses can implement to provide the values for the choices this could be achieved. The serializer would be written as so.
The same template syntax could be used and the rendered HTML would now be.
And the user (staff) sees this in the browser.
Related discussion group.
The text was updated successfully, but these errors were encountered:
Thanks James - appreciate the in-depth issue.
I think something like
A pull request here would be great. I guess that the best place to include this in the docs would be somewhere in the "further notes" for serializer relations. - http://www.django-rest-framework.org/api-guide/relations/#further-notes