From 02ede72ce9ddeb4d7d7241503585bb07fe3e2c50 Mon Sep 17 00:00:00 2001 From: Kyle McFarland Date: Sat, 20 Oct 2018 21:51:14 -0600 Subject: Allow suppliers to have multiple representatives This adds a basic Representative model and allows for editing them in the admin interface both in the Suppliers admin panel for each supplier and in a new Representatives admin panel which allows bulk editing of all representatives. Currently multiple representatives are just listed in the component view as extra rows below the company row but it would probably make sense to add a view for viewing suppliers directly. The REST API has also been slightly modified to return a list of representatives for each supplier in the components endpoint, adding a suppliers endpoint would probably also be a good idea. Requires running: $ python manage.py migrate procurement 0002_add_representative To update the database for the new model, both forward and lossy reverse data migration is implemented in the migration. --- procurement/models.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'procurement/models.py') diff --git a/procurement/models.py b/procurement/models.py index 1e70736..43e5a07 100644 --- a/procurement/models.py +++ b/procurement/models.py @@ -51,19 +51,25 @@ class DashboardModel(models.Model): base_string = 'updated {quantity:.2f} {units} ago' return base_string.format(quantity=quantity, units=units) - class Supplier(DashboardModel): """ Model which represents an individual or organisation which supplies components """ name = models.CharField(max_length=255) - representative_name = models.CharField(max_length=255, null=True, blank=True) - representative_email = models.EmailField(max_length=255, null=True, blank=True) is_authorized = models.BooleanField() def __str__(self): return '{}'.format(self.name) +class Representative(DashboardModel): + """Model which represents a single Representative, each supplier + can have multiple representatives""" + name = models.CharField(max_length=255) + email = models.CharField(max_length=255) + supplier = models.ForeignKey(Supplier, on_delete=models.CASCADE, related_name="representatives", null=True, blank=True) + + def __str__(self): + return '{} <{}>'.format(self.name, self.email) class Component(DashboardModel): """ -- cgit v1.1