Member-only story
Optimal way to add custom fields to Django admin
One of the best practices in software development is to reduce as much database queries as possible through optimisation. A good Software developer must always have optimisation in mind when architecting a software product.
In this article I will be showing two ways to add custom fields to Django admin and explain which is best for what scenario.
Option 1 — using the @property method
The @property method in python allows you to attach additional calculated attributes which can then be used in the Django admin. I will show an example of how to use it before addressing the pros and cons.
There are 78 books currently in the sample database i am using and 5,098,648 books already read by users
Scenario 1 — where there isn’t much computation going on, speed is negligible and there are no extra database queries. It’s simple to use and no extra database calls is invoked