15👍
✅
I believe the keys of a dict are not guaranteed to be sorted (unless you use OrderedDict
obviously). That is, you “might” get “Offline”, “Dev”, “Live” choices with your version.
Implementation note on dict.items:
Keys and values are listed in an arbitrary order which is non-random, varies across Python implementations, and depends on the dictionary’s history of insertions and deletions.
3👍
Expanding on my comment on @vicvicvic’s answer:
t = [ 'Live', 'Offline', 'Dev', ]
status = models.SmallIntegerField( choices=[(i,t[i]) for i in range(len(t))] )
...
if not 0 <= int(input1) < len(t): print "invalid"
if input2 not in t: print "invalid"
status = t.index(input2)
👤Jake
- Graphene Django – Mutation with one to many relation foreign key
- Access token from view
- How to set environmental variables properly Gitlab CI/CD and Docker
- Django development server and MIME types
- Best way to denormalize data in Django?
Source:stackexchange.com