diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-01-21 18:03:43 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-01-21 18:04:15 +0000 |
commit | 5f06e5559c00db759574467c3884a4645346b224 (patch) | |
tree | 8fcd68579d7441823da3e90d913a0694fc65855e /ctrack/organisations/models.py | |
parent | 490fc024506c9ed9f9c0b5a4cfbcdecc95127dbe (diff) |
reconfigured Address and Organisation relationship
Diffstat (limited to 'ctrack/organisations/models.py')
-rw-r--r-- | ctrack/organisations/models.py | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/ctrack/organisations/models.py b/ctrack/organisations/models.py index cf8e7de..6bd1249 100644 --- a/ctrack/organisations/models.py +++ b/ctrack/organisations/models.py @@ -9,7 +9,20 @@ class AddressType(models.Model): descriptor = models.CharField(max_length=50) +class Organisation(models.Model): + name = models.CharField(max_length=255, blank=False) + + def get_absolute_url(self): + return reverse("organisations:detail", kwargs={"name": self.slugify_name()}) + + def slugify_name(self): + return slugify(self.name) + + class Address(models.Model): + organisation = models.ForeignKey( + Organisation, related_name="addresses", on_delete=models.CASCADE, blank=False + ) type = models.ForeignKey(AddressType, on_delete=models.CASCADE, default=1) line1 = models.CharField(max_length=255) line2 = models.CharField(max_length=255) @@ -19,14 +32,3 @@ class Address(models.Model): postcode = models.CharField(max_length=10) country = models.CharField(max_length=100) other_details = models.CharField(max_length=255) - - -class Organisation(models.Model): - name = models.CharField(max_length=255, blank=False) - address = models.ForeignKey(Address, on_delete=models.CASCADE, blank=True, null=True) - - def get_absolute_url(self): - return reverse("organisations:detail", kwargs={"name": self.slugify_name()}) - - def slugify_name(self): - return slugify(self.name) |