Django table or Dict: performance?

Viewed 20

I have multiple small key/value tables in Django, and there value never change

ie: 1->"Active", 2->"Down", 3->"Running"....

and multiple times, I do some get by id and other time by name. So I'm asking, if it's not more optimize to move them all as Dict (global or in models) ? thank you

1 Answers

Generally django querysets are slower than dicts, so if you want to write model with one field that has these statuses (active, down, running) it's generally better to use dict until there is need for editability.

Anyway I don't understand this kind of question, the performance benefits are not really high until you got ~10k+ records in single QS, and even by then you can cast the whole model to list by using .values_list syntax. Execution will take approximately part of second.

Also if I understand, these values should be anyway in models.CharField with choices field set, rather than set up by fixture in models.ForeignKey.

Related