0

I want to add product to category model in admin page.

models.py

class Product(models.Model):
    name = models.CharField(max_length=20)
    image = models.ImageField(upload_to='product/')

    def __str__(self):
        return self.name

class Categorymodels.Model):
    category_name = models.CharField(max_length=20)
    category_product = models.ManyToManyField(Product, blank=True, related_name='category_product')

    def __str__(self):
        return self.promo_name

admin.py

@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
    filter_horizontal = ('category_product', )
    pass

When adding products to category, I can use filtering but it filters only by product name. How do I filter something else.

Parca
  • 21
  • 5

0 Answers0