Josh Cartmell committed f3e2496

Add template tag to list product and it's subclasses in the admin.

Comments (0)

Files changed (3)


     def __init__(self, *args, **kwargs):
-        For ``Product`` subclasses that are registered with an Admin class
+        For ``Page`` subclasses that are registered with an Admin class
         that doesn't implement fieldsets, add any extra model fields
         to this instance's fieldsets. This mimics Django's behaviour of
         adding all model fields when no fieldsets are defined on the


         verbose_name = _("Product")
         verbose_name_plural = _("Products")
+    @classmethod
+    def get_content_models(cls):
+        """
+        Return all Page subclasses.
+        """
+        is_content_model = lambda m: m is Product or issubclass(m, Product)
+        return filter(is_content_model, models.get_models())
     def get_content_model(self):
         Provides a generic method of retrieving the instance of the custom


 from decimal import Decimal
 import locale
-from django import template
+from django.core.urlresolvers import NoReverseMatch
+from mezzanine import template
+from mezzanine.utils.urls import admin_url
 from import set_locale
     return context
+def models_for_products(*args):
+    """
+    Create a select list containing each of the models that subclass the
+    ``Product`` model and the ``Product`` model itself.
+    """
+    product_models = []
+    for model in Product.get_content_models():
+        try:
+            admin_url(model, "add")
+        except NoReverseMatch:
+            continue
+        else:
+            setattr(model, "name", model._meta.verbose_name)
+            setattr(model, "add_url", admin_url(model, "add"))
+            product_models.append(model)
+    return product_models
 @register.inclusion_tag("shop/includes/order_totals.html", takes_context=True)
 def order_totals(context):