Closed asing177 closed 8 years ago
Filtering by brand is something more complicated than just changing your template and models. You also need to do some work in views.py.
This would take time, and this question is not related to the sources of this repo. I cannot write your code for you. Learn django basics on djangoproject.com.
P.S.
You don't need TreeForeignKey
in your Product
model, and default=''
in ForeignKey is also nonsense. Your related_name='brand'
is ambiguous, make it more verbose and explanatory. Correct your model:
class Product(models.Model):
brand = ForeignKey('Brand', verbose_name='brands', related_name='products')
category = ForeignKey('Category', verbose_name='categories', related_name='products' )
i am a beginner in django mptt urls....thanks in advance
class Category(MPTTModel): title = models.CharField(max_length =120) parent = TreeForeignKey('self' , null = True , blank = True , verbose_name='parent category', related_name='categories') def get_absolute_url(self): return reverse('categories', kwargs={'path': self.get_path()}) def get_clothes(self): return Product.objects.filter(category__in=self.get_descendants(include_self=True))
class Product(models.Model): brand = ForeignKey('Brand', verbose_name='brands', related_name='brand' , default='') category = TreeForeignKey('Category', verbose_name='categories', related_name='products' , default='')
i have categories like this men > men clothing > tshirts
my template {% for product in instance.get_clothes %} {{ product.title }} {% endfor %}
how can i filter based on brand and still show the result on the same template ?