[Answer]-Django – how to create duplicate apps without duplicating the code (models, signals and so on)

1πŸ‘

βœ…

You should move all the identical code to the app_shared application and import it from app_company1 and app_company2.

If have separate tables in the DB is a requirement, then the inventory and transaction models should be defined as abstract in app_shared. app_company1 and app_company2 should create their own corresponding models that derive from the abstract models. This will ensure separate tables are generated in the DB. See this documentation page for more details.

πŸ‘€OrenD

0πŸ‘

The issue is, between app_company1 and app_company2, everything is identical, same exact models, signals and so on. I have to keep them separate to create their own tables in database. But don’t want to duplicate same code. Is there a way of preventing the duplication?

If you have such code then your design of apps is not perfect. You can try to make one app for app_company and try to distinguish between records of different companies. That way you can add as many companies as you want without duplicating the code or adding new app for each one of them.

πŸ‘€Rohan

Leave a comment