django-model-utils icon indicating copy to clipboard operation
django-model-utils copied to clipboard

what about Choices.max_length ?

Open AlexDaniel opened this issue 5 years ago • 0 comments

Looking at the documentation:

from model_utils import Choices

class Article(models.Model):
    STATUS = Choices('draft', 'published')
    status = models.CharField(choices=STATUS, default=STATUS.draft, max_length=20)

Wouldn't it be better to have something like:

    status = models.CharField(choices=STATUS, default=STATUS.draft, max_length=STATUS.max_length)

That is, Choices can provide a method for figuring out the length of the longest choice. This way a little bit less thinking is required when you need to come up with the right length.

AlexDaniel avatar Jan 06 '21 06:01 AlexDaniel