"Don't try to do everything from scratch."
Generating Admin UI by yourself could be painful Link to heading
If you’re a software engineer, you’ve likely encountered admin tools in your work. Regardless of the type of web application you’re developing, an admin tool or interface is essential. However, many engineers don’t want to devote a lot of time to admin tools because they aren’t customer-facing apps. As a result, admin tools are often implemented with minimal effort, leading to lower quality compared to customer-facing apps.
To address these issues, there are now more tools available to quickly create admin UIs for modern applications. Django Admin is the top choice among these tools due to its flexibility, high level of customization and ease of development.
How to integrate Django Admin to your existing system Link to heading
Prerequisites Link to heading
- You should be familiar with Python 3 & Django
- If you are new to Django and want to learn it, this is a good place to start: MDN Django tutorial
Before you start Link to heading
From my prior experience, there are two things to be considered before integrating Django Admin:
-
Database Instances: how many database are there in your system? is it ok to create the Django Admin tables in the main database?
- If there is just one database and there is no restriction about the table location, that’s easy. Just go ahead, that’s quite easy!
- If there are multiple databases and you have to put the Django Admin tables in a separated database, additional customizations are required to make things work. You can refer to the next example section for it.
-
Authentication & Authorization mechanism: Django admin provides a built-in authentication system and it’s very powerful. However, in a specific situation, you might not be allowed to use it and you have to make use of an existing authentication system. At that time, you will have to customize Django’s authentication backend to serve that requirement. I will cover it in another article.
Example Project Link to heading
[Django Admin legacy database integration](https://github.com/jeebb/django-admin-legacy-db-integrtion) .
-- <Copy from README.md> –
Integrate Django Admin into a legacy database
Link to heading
This is an example for integrating Django Admin into a legacy database:
-
Legacy database & Django Admin are in the different databases
-
Sqlite is used for demonstrating purpose (
admin_db.sqlite3; legacy_db.sqlite3)
-
The files to be checked are
settings.py (DATABASES & DATABASE_ROUTERS config)
db_routers.py
admin.py
models.py
Refer to the django documentation for more info:
https://docs.djangoproject.com/en/4.2/topics/db/multi-db/
https://docs.djangoproject.com/en/4.2/howto/legacy-databases/
-- </Copy from README.md> –
Things to pay attention Link to heading
- Be careful with the CUD operations (create, update, delete) when integrating Django Admin with an existing system. In an existing system, then performing CUD operations, there often be extra business logic to be performed beside updating things in database. In that case, instead of of using the default actions of django admin, you should override the update form behavior to implement custom business logic to match with the rest of the system. The best way is to call the APIs provided by the main project to avoid maintaining business logics in different places.
- You should spend extra effort on synchronizing the changes of database schema to the related Django model classes or Django admin might not work as expected. Remember that the database schema should be managed by the main project, not by Django, because you are integrating to a legacy system.
- Since Django Admin allows accessing to many important data, you should consider adding extra security layers (e.g MFA, IP restriction …) to prevent hacking or unauthorized access.
There are always “pros” and “cons” Link to heading
I will just mentions about the “cons” cuz the “pros” is quite clear:
- Learning curve (Python, Django & Django Admin).
- UI/UX might not be consistent with the rest of the system.
- The frontend part is not “trendy” (jQuery). If you are expecting something like a SPA with ReactJs, Vue … , it’s not for you.
Conclusion Link to heading
Integrating Django admin into a legacy system can provide significant benefits, such as improved usability and better data management. However, it also requires careful planning and consideration to ensure a seamless integration with existing systems and processes. With the right approach, integrating Django admin can help provide long-term benefits for an organization.
Keep calm and good things will come!
Subscribe to our newsletter • About the author