diff --git a/apps/shop/admin.py b/apps/shop/admin.py index 4de2695..bed96ce 100644 --- a/apps/shop/admin.py +++ b/apps/shop/admin.py @@ -20,7 +20,8 @@ class ProductAdmin(admin.ModelAdmin): @admin.register(Category) class CategoryAdmin(admin.ModelAdmin): - list_display = ['name', 'slug'] + list_display = ['name', 'slug', 'is_active'] + fields = ['name', 'slug', 'is_active'] prepopulated_fields = {'slug': ('name', )} diff --git a/apps/shop/models.py b/apps/shop/models.py index 7ef8c07..6234e37 100644 --- a/apps/shop/models.py +++ b/apps/shop/models.py @@ -9,6 +9,11 @@ def get_queryset(self): return super(ProductManager, self).get_queryset().filter(is_active=True) +class CategoryManager(models.Manager): + def get_queryset(self): + return super(CategoryManager, self).get_queryset().filter(is_active=True) + + class Category(TimestempedAbstractModel, SlugstempedAbstractModel): """ Category Table implimented with MPTT. @@ -22,6 +27,10 @@ class Category(TimestempedAbstractModel, SlugstempedAbstractModel): ) is_active = models.BooleanField(default=True) + # Managers + objects = models.Manager() + categories = CategoryManager() + class Meta: verbose_name = _("Category") verbose_name_plural = _("Categories") @@ -46,6 +55,8 @@ class Product(TimestempedAbstractModel, SlugstempedAbstractModel): price = models.DecimalField(max_digits=10, decimal_places=2) is_stock = models.BooleanField(default=True) is_active = models.BooleanField(default=True) + + # Managers objects = models.Manager() products = ProductManager()