From 9cbf48383c58d5cdd29f2a150577ec23a54305f0 Mon Sep 17 00:00:00 2001 From: Seth Ladygo Date: Thu, 13 Feb 2020 16:38:11 -0800 Subject: [PATCH] products/models.py: add UPC class --- products/dbrouters.py | 12 +++++++++--- products/models.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/products/dbrouters.py b/products/dbrouters.py index eafcfa3..5d329be 100644 --- a/products/dbrouters.py +++ b/products/dbrouters.py @@ -1,14 +1,20 @@ -from products.models import Product, SeasonRegionMaterial +from products.models import Product, SeasonRegionMaterial, UPC class ProductDBRouter(object): + def is_product_class(self, model): + return \ + model == Product or \ + model == SeasonRegionMaterial or \ + model == UPC + def db_for_read(self, model, **hints): - if model == Product or model == SeasonRegionMaterial: + if self.is_product_class(model): return 'products' return None def db_for_write(self, model, **hints): - if model == Product or model == SeasonRegionMaterial: + if self.is_product_class(model): return 'products' return None diff --git a/products/models.py b/products/models.py index f4b9b82..f8a4a87 100644 --- a/products/models.py +++ b/products/models.py @@ -125,3 +125,16 @@ class SeasonRegionMaterial(models.Model): class Meta: managed = False db_table = "keen_season_region_material" + + +class UPC(models.Model): + upc = models.CharField(max_length=20, db_column='upc', primary_key=True) + size = models.CharField(max_length=20, db_column='size') + dimension = models.CharField(max_length=20, db_column='dimension') + material = models.CharField(max_length=10, db_column='material') + size_grid = models.CharField(max_length=20, db_column='size_grid') + updated = models.DateTimeField() + + class Meta: + managed = False + db_table = "keen_upc"