Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatible with django_model_utils Choices #78

Closed
dbinetti opened this issue Mar 15, 2016 · 4 comments
Closed

compatible with django_model_utils Choices #78

dbinetti opened this issue Mar 15, 2016 · 4 comments

Comments

@dbinetti
Copy link

I am using @carljm's django_model_util Choices field. is this package compatible? i ask because i am trying to create a filter that uses the human-readable version of the choices field backing a model field, and can't get it to work. if it is compatible, i'd love a concrete example to follow. thanks...

@rpkilby
Copy link
Collaborator

rpkilby commented Mar 15, 2016

Hi @dbinetti. Looking over the code, the choices field is just a regular CharField that pulls its choices from the parent model, so it would exhibit the same characteristics as the underlying field.

What are you're trying to accomplish by using the human-readable value instead of the code value? Could you provide a concrete example?

Using the human-readable value is generally problematic, as this is a display value subject to transformation (language translation, capitalization, etc...). The code values are more durable since they aren't transformed.

@dbinetti
Copy link
Author

I'm trying to make the URL human readable (and fungible directly). However, your point about transformation makes good sense. I'll let this go.

@rpkilby
Copy link
Collaborator

rpkilby commented Mar 16, 2016

I'd say your best bet is to use code values that are human friendly.

eg,

# Use:
STATUSES = (
    ('started', 'Started'),
    ('in_progress', 'In Progress'),
    ('finished', 'Finished'),
    ('errored', 'Errored'),
)

# instead of
STATUSES = (
    ('s', 'Started'),
    ('p', 'In Progress'),
    ('f', 'Finished'),
    ('e', 'Errored'),
)

@dbinetti
Copy link
Author

actually, i'm using integers (order is important) motel_utils allow for a
three-tuple (1,'foo', 'Foo Bar'), so that would potentially work, but i
think i'll just work things on the front end appropriately.

tks

On Wed, Mar 16, 2016 at 1:43 PM, Ryan P Kilby notifications@github.com
wrote:

I'd say your best bet is to use code values that are human friendly.

eg,

Use:STATUSES = (

('started', 'Started'),
('in_progress', 'In Progress'),
('finished', 'Finished'),
('errored', 'Errored'),

)

instead ofSTATUSES = (

('s', 'Started'),
('p', 'In Progress'),
('f', 'Finished'),
('e', 'Errored'),

)


You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub
#78 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants