I'm working with Django 2.1 on a fairly simple application and I'm struggling to find a pattern I'm convinced with when dealing with app decoupling.
Right now I have a simple sales app and a taxes app. The taxes app references the Customer model in the sales app in a model I called Contributor which contains the tax information for a specific customer. Here is a simplified version.
#sales/models.py
class Customer(models.Model):
name = models.CharField()
address = models.CharField()
email = models.CharField()
#taxes/models.py
class Contributor(models.Model):
customer = models.ForeignKey(sales.models.Customer)
tax_id = models.CharField()
sales_tax_type = models.CharField()
What I would like to do is to be able to keep these apps loosely coupled so if I needed to replace the taxes app entirely the sales app wouldn't even care. The problem arises when I need to perform lookups based on fields on both tables, for instance I need to retrieve customers containing a string in their names and having a certaing sales_tax_type. Right now I'm querying in the taxes app by referencing the customer attributes. This aproach I don't really like because it requires me to query based on the customer model specifically and later on I may require contributor data for other models (like Provider for instance).
I have also thought about denormalizing the customer into the contributor and have a few different classes inherit from Contributor for each type.
If anyone has a better idea it'd be awesome.
Thank you!