Skip to content

Commit

Permalink
update product, category models add Category Manager and change admin…
Browse files Browse the repository at this point in the history
… panel
  • Loading branch information
RustamovAkrom committed Sep 18, 2024
1 parent 5d4da1d commit 6093e95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion apps/shop/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', )}


Expand Down
11 changes: 11 additions & 0 deletions apps/shop/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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")
Expand All @@ -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()

Expand Down

0 comments on commit 6093e95

Please sign in to comment.