Permalink
Browse files

Added abstract base class for Product.

Defining the manager on an abstract base class means subclasses will
inherit it instead of having to explicitly define their own.
  • Loading branch information...
1 parent 542689c commit 2941f5539273d44659c88ae6daa9a9136f99f4fe @AlexHill committed Jan 10, 2013
Showing with 14 additions and 3 deletions.
  1. +14 −3 cartridge/shop/models.py
View
@@ -87,7 +87,20 @@ def copy_price_fields_to(self, obj_to):
obj_to.save()
-class Product(Displayable, Priced, RichText, AdminThumbMixin):
+class BaseProduct(Displayable):
+ """
+ Exists solely to store ``DisplayableManager`` as the main manager.
+ If it's defined on ``Product``, a concrete model, then each
+ ``Product`` subclass loses the custom manager.
+ """
+
+ objects = DisplayableManager()
+
+ class Meta:
+ abstract = True
+
+
+class Product(BaseProduct, Priced, RichText, AdminThumbMixin):
"""
Container model for a product that stores information common to
all of its variations such as the product's title and description.
@@ -108,8 +121,6 @@ class Product(Displayable, Priced, RichText, AdminThumbMixin):
verbose_name=_("Upsell products"), blank=True)
rating = RatingField(verbose_name=_("Rating"))
- objects = DisplayableManager()
-
admin_thumb_field = "image"
class Meta:

0 comments on commit 2941f55

Please sign in to comment.