Opened 4 years ago

Closed 4 years ago

#32123 closed New feature (wontfix)

Add properties `is_xxx` for django.db.models.enums

Reported by: Kwist Owned by: Kwist
Component: Database layer (models, ORM) Version: 3.1
Severity: Normal Keywords: enums
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

For example:

from django.db import models

class Suit(models.IntegerChoices):
    DIAMOND = 1, _('Diamond')
    SPADE = 2, _('Spade')
    HEART = 3, _('Heart')
    CLUB = 4, _('Club')

This feature allows use

if value.is_heart: 
    ...

instead of

if value == Suit.HEART: 
    ...

if value is Suit.HEART: 
    ...

if value == 3: 
    ...

Change History (2)

comment:1 by Kwist, 4 years ago

Has patch: set
Owner: changed from nobody to Kwist
Status: newassigned

comment:2 by Carlton Gibson, 4 years ago

Resolution: wontfix
Status: assignedclosed

Hi. Thanks for the idea.

I'd say that the additional code is not worth the non-standard API here. You're welcome to add such properties on your own subclasses, but they just add second way of doing things, which we try to avoid.

Note: See TracTickets for help on using tickets.
Back to Top