Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8591493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:32:27+00:00 2026-06-11T23:32:27+00:00

I am trying to figure out whether I can represent model field choices to

  • 0

I am trying to figure out whether I can represent model field choices to clients consuming a tastypie API.

I have a django (1.4.1) application for which I am implementing a django-tastypie (0.9.11) API. I have a Model and ModelResource similar to the following:

class SomeModel(models.Model):
    QUEUED, IN_PROCESS, COMPLETE = range(3)

    STATUS_CHOICES = (
        (QUEUED, 'Queued'),
        (IN_PROCESS, 'In Process'),
        (COMPLETE, 'Complete'),
    )

    name = models.CharFIeld(max_length=50)
    status = models.IntegerField(choices=STATUS_CHOICES, default=QUEUED)

class SomeModelResource(ModelResource):
    class Meta:
        queryset = SomeModel.objects.all()
        resource_name = 'some_model'

When I look at objects in the API, the name and status fields are displayed as follows:

{
    ...
    "objects":[
    {
        "name": "Some name 1",
        "status": 0
    },
    {
        "name": "Some name 2",
        "status": 2
    }]
}

I know I can alter SomeModelResource with hydrate/dehydrate methods to display the string values for status as follows, which would have more value to clients:

{
    ...
    "objects":[
    {
        "name": "Some name 1",
        "status": "Queued"
    },
    {
        "name": "Some name 2",
        "status": "Complete"
    }]
}

But how would the client know the available choices for the status field without knowing the inner workings of SomeModel?

Clients creating objects in the system may not provide a status as the default value of QUEUED is desirable. But clients that are editing objects need to know the available options for status to provide a valid option.

I would like for the choices to be listed in the schema description for SomeModelResource, so the client can introspect the available choices when creating/editing objects. But I am just not sure whether this is something available out of the box in tastypie, or if I should fork tastypie to introduce the capability.

Thanks for any feedback!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:32:28+00:00Added an answer on June 11, 2026 at 11:32 pm

    You can add the choices to the schema by overriding the method in your resource. If you would want to add the choices to any field (maybe to use with many resources), you could create the method as follows:

    def build_schema(self):
        base_schema = super(SomeModelResource, self).build_schema()
        for f in self._meta.object_class._meta.fields:
            if f.name in base_schema['fields'] and f.choices:
                base_schema['fields'][f.name].update({
                    'choices': f.choices,
                })
        return base_schema
    

    I haven’t tested the above code but I hope you get the idea. Note that the object_class will be set only if you use the tastypie’s ModelResource as it is being get from the provided queryset.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out whether wordpress can handle the following requirements for a
hoping someone can help me out with this. I'm trying to figure out whether
I'm trying to figure out how to accomplish the following: User can have many
I have been trying to figure out whether it is possible to use only
I have spent all morning trying to figure out how I can call a
I am trying to figure out whether I can use protobuf-net to store and
I'm trying to figure out whether Clojure is something that can fully replace the
I'm trying to figure out whether the code located after throw new Exception in
I am trying to figure out whether or not the current date falls within
I’m trying to figure out whether FormsAuthentication.RedirectFromLoginPage (called inside method M() ), performs redirection

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.