Thursday, April 26, 2018

Things in Django I constantly forget

There are some things in Django I constantly forget!

Getting the friendly value for a enum value


You have model:

class MyModel(models.Model)
    thing = models.IntegerField(choices=SOME_CHOICES)

You want the value for thing:
happy_value = my_instance.get_thing_valuedisplay()


Use the free jupyter shell that comes with django extensions

pip3 install jupyter
or
python -m pip install jupyter
then
python manage.py shell_plus --notebook

No comments: