I would definitely use an enum field that used pep 435 enums instead of 
choices. The implementation as a real enum in postgres and choices on other 
databases is perfect. I've used a third-party 
package, https://github.com/hzdg/django-enumfields, to accomplish this in 
the past. The ability to use real python enums is a great improvement over 
defining constants for each choice yourself.

On Wednesday, February 25, 2015 at 7:53:34 PM UTC-7, Thomas Stephenson 
wrote:
>
> As discussed in Issue 24342 <https://code.djangoproject.com/ticket/24342>, 
> I've got an implementation of EnumField that we've found useful when 
> developing our django REST API that I'd like to add to django core. It was 
> suggested I bring this issue up in the developers mailing list for 
> discussion. Unfortunately, updates to the issue were delivered to my spam 
> folder, so there has been some delay in actually raising the issue.
>
> Basically, the implementation consists of a new field type, and a new 
> migration operation (to register the values associated with an enum type). 
> The field takes an `enum_type` argument and registers a type with values 
> taken from the enum value names. The actual values associated with the 
> names are ignored, so support for IntEnum and other enum types comes as 
> standard.
>
> In a real implementation, the enum type would have to be checked when 
> running migrations to ensure that values haven't been added/removed from 
> the python class. It's not something that we've needed to deal with in our 
> in-house implementation.
>
> Any database which does not support an enum field natively would default 
> to a CharField implementation. 
>
> Useful addition? Or does it overlap too much with the choices API? 
>
> Thomas
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/ba1294df-7fea-4f46-b5ff-3d6ad3909cda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to