Search code examples
pythondjangoresttastypie

Django-tastypie - how to include choices?


I have a model field like this

location_state = models.CharField(max_length=255, null=True, blank=True, choices=STATE_CHOICES)

Its value is returned by tastypie, but for rendering a listbox a list of all available choices is needed. What's the best way to expose such choices via a resource?


Solution

  • I'd use the built-in schema to inform the client about field options. Still, choice options are not included in the schema resource by default. This thread shows one way how to achieve this.

    Edit 2013-03-19:

    Alternatively you could add your choices to the meta field by using / overriding the alter_list_data_to_serialize method in your ModelResource.