Skip to content

Remove the need for a user profile. #3

Description

@vandorjw

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions