Currently the model looks like the following:
class Invoice(models.Model):
user = models.ForeignKey(User)
currency = models.ForeignKey(Currency, blank=True, null=True)
address = models.ForeignKey(Address, related_name='%(class)s_set')
What do you think of breaking out the user, currency, and address, and instead, linking Invoice to 'Customer' in the following manner.
class Country(models.Model):
name = models.CharField( ... )
...
class Region(models.Model): # state/province/region
country = models.ForeignKey(Country)
...
class Locality(models.Model): # city/town/hamlet
region = models.ForeignKey(Region)
...
class Address(models.Model):
locality = models.ForeignKey(Locality)
...
class Currency(models.Model):
country = models.ManyToManyField(Country)
...
class Customer(models.Model):
address = models.ForeignKey(Address)
...
class Invoice(models.Model):
customer = models.ForeignKey(Customer)
def address(self):
return self.customer.address
def currency(self):
return self.customer.address.city.state.country.currency
A currency is an attribute of a country. However, a currency has nothing to do with an address. We could even add official_languages as a field to County, and have translations based on that, but it would be difficult to know when to stop. So that being said, maybe it is best to keep currency as a field in invoice.
Let me know what you think.
I forked and made some changes, but won't make a PR until I write test, and make sure everything works.
Currently the model looks like the following:
What do you think of breaking out the user, currency, and address, and instead, linking Invoice to 'Customer' in the following manner.
A currency is an attribute of a country. However, a currency has nothing to do with an address. We could even add official_languages as a field to County, and have translations based on that, but it would be difficult to know when to stop. So that being said, maybe it is best to keep currency as a field in invoice.
Let me know what you think.
I forked and made some changes, but won't make a PR until I write test, and make sure everything works.