OK, this is CLOSE and it may even work....maybe someone else can correct
it, because I may have category/product backwards, and I put a filter in
there so you can search for a product by attribute, but you'll have to
tweak it...

category_view.html

{% extends "base.html" %}
{% block content %}
<h3 align="center"> Products in a Category </h3>
<form method="get">
    {{ object_list.form.as_p }}
  <button type="submit">Search</button>
</form>
{% for object in object_list.qs%}
{% include 'category-inline.html'%}
{% endfor %}
{% endblock %}




category_inline.html

<div class='col-80 col-md-100 mb-1 mx-auto'>
<div class='card'>
  <div class='card-body'>
<h5 class = 'card-title'>
<p>{{object.name}}-{{object.slug}}</p>
{% for product in object.category.category.all %}
{{product.name}}--{{product.slug}}--{{product.brand}}--
{{product.available}}{{product.stock}}
{% endfor %}


views.py

from .filters import ProductFilter

def category_view(request):
my_title = "Products"
qs = Category.objects.prefetch_related('category__category')
category_list = ProductFilter(request.GET, queryset=qs)
template_name = 'category_view.html'
context = {'object_list': category_list,"title":my_title}
return render (request, template_name, context)



filters.py


class ProductFilter(django_filters.FilterSet):
category__name =
django_filters.CharFilter(lookup_expr='icontains',label='Product Name
contains')
class Meta:
model = Product
fields = {
        }


Charlotte Wood, MEd

Educator

(405) 578-5701

Zoom Meeting ID#: 4055785701

*Zoom URL:* https://epiccharterschools.zoom.us/j/2970513912

Classroom Google Site:
https://sites.google.com/epiccharterschools.org/charlottewoodclassroom/home

Epic Technical Support: (405) 652-0935



Jordan McKesson Principal

405-749-4550 ext. 309

jordan.mckes...@epiccharterschools.org

<http://facebook.com/epiccharterschools> <https://twitter.com/epiccharter>
<https://www.instagram.com/epiccharterschools/>
<https://www.youtube.com/user/EpicCharterSchools>




On Wed, Jul 3, 2019 at 6:37 PM Tosin Ayoola <tosinayoo...@gmail.com> wrote:

> this' my model
> from django.db import models
> from django.shortcuts import reverse
>
> class Category(models.Model):
> name = models.CharField(max_length = 100, db_index = True)
> slug = models.SlugField(max_length = 130, db_index= True, unique = True)
> class Meta:
> db_table = 'categories'
> verbose_name = 'catergories'
>
> def __str__(self):
> return self.name
>
> def get_absolute_url(self):
> return reverse("category-detail", args=[self.slug])
>
> def get_product(self):
> return Product.objects.filter(category= self.name)
>
>
> class Product(models.Model):
> name = models.CharField(max_length = 100, db_index = True)
> slug = models.SlugField(max_length= 100, db_index= True)
> brand = models.CharField(max_length = 100)
> available = models.BooleanField(default= True)
> meta_keywords = models.CharField(max_length = 150, blank = True)
> stock = models.PositiveIntegerField()
> updated = models.DateTimeField(auto_now= True)
> price = models.DecimalField(max_digits = 10, decimal_places = 2, default =
> 0.00)
> image = models.ImageField(upload_to = 'product_imgs', blank = True)
> best_seller = models.BooleanField(default=False)
> category = models.ForeignKey(Category, on_delete = 'MODEL.CASCADE',
> related_name='product')
> description = models.TextField()
> created = models.DateTimeField()
>
> class meta:
> db_name = 'Product'
> ordering = [' -created']
> index_together = (('id', 'slug'),)
>
> def __str__(self):
> return self.name
>
> def get_absolute_url(self):
> return reverse("product-detail", args= [self.slug,
> self.created.year,
> self.created.strftime('%m'),
> self.created.strftime('%d')])
>
> On Thu, Jul 4, 2019 at 12:33 AM Charlotte Wood <
> charlotte.w...@epiccharterschools.org> wrote:
>
>> and, are you using a base.html?  and a form.html?  then customizing the
>> template for the product_view?
>>
>>
>>
>> Charlotte Wood, MEd
>>
>> Educator
>>
>> (405) 578-5701
>>
>> Zoom Meeting ID#: 4055785701
>>
>> *Zoom URL:* https://epiccharterschools.zoom.us/j/2970513912
>>
>> Classroom Google Site:
>> https://sites.google.com/epiccharterschools.org/charlottewoodclassroom/home
>>
>> Epic Technical Support: (405) 652-0935
>>
>>
>>
>> Jordan McKesson Principal
>>
>> 405-749-4550 ext. 309
>>
>> jordan.mckes...@epiccharterschools.org
>>
>> <http://facebook.com/epiccharterschools>
>> <https://twitter.com/epiccharter>
>> <https://www.instagram.com/epiccharterschools/>
>> <https://www.youtube.com/user/EpicCharterSchools>
>>
>>
>>
>>
>> On Wed, Jul 3, 2019 at 6:32 PM Charlotte Wood <
>> charlotte.w...@epiccharterschools.org> wrote:
>>
>>> What is the name of the field in your model?  ie:  Title, Name, etc....
>>> so one option would be product.title   or product.name....
>>>
>>> can you just put your model in here?
>>>
>>>
>>> Charlotte Wood, MEd
>>>
>>> Educator
>>>
>>> (405) 578-5701
>>>
>>> Zoom Meeting ID#: 4055785701
>>>
>>> *Zoom URL:* https://epiccharterschools.zoom.us/j/2970513912
>>>
>>> Classroom Google Site:
>>> https://sites.google.com/epiccharterschools.org/charlottewoodclassroom/home
>>>
>>> Epic Technical Support: (405) 652-0935
>>>
>>>
>>>
>>> Jordan McKesson Principal
>>>
>>> 405-749-4550 ext. 309
>>>
>>> jordan.mckes...@epiccharterschools.org
>>>
>>> <http://facebook.com/epiccharterschools>
>>> <https://twitter.com/epiccharter>
>>> <https://www.instagram.com/epiccharterschools/>
>>> <https://www.youtube.com/user/EpicCharterSchools>
>>>
>>>
>>>
>>>
>>> On Wed, Jul 3, 2019 at 6:25 PM Tosin Ayoola <tosinayoo...@gmail.com>
>>> wrote:
>>>
>>>> Good day guyz
>>>> sorry i'm working on a django e-commerce project which i am new to, and
>>>> i'm stuck, i wan have a page that will display the list of all for the list
>>>> of all products under a particular category, which i have checked out on
>>>> stackoverflow, i tried every suggestion and yet since not working below is
>>>> my code hoping anyone can lead mr in d right direction
>>>>
>>>> ##View
>>>>
>>>> def index(request):
>>>> products = Product.objects.all()
>>>> category = get_list_or_404(Category)
>>>> cat = Category.objects.filter(pk = id)
>>>> return render(request, 'shop/index.html', locals())
>>>>
>>>> ##product_list Page
>>>> <h2>Categories</h2>
>>>> {% if cat %}
>>>> <ul>
>>>> {% for c in cat %}
>>>> <li>
>>>> <a href="{% url 'product-list' %}"> {{c.name}}</a>
>>>> </li>
>>>> {% for product in cat.get_product %}
>>>> <p> {(product.name}}</p>
>>>> {% endfor %}
>>>> {% endfor %}
>>>> </ul>
>>>> {% else %}
>>>> <p> There's no item category yet
>>>> {% endif %}
>>>> </div>
>>>>
>>>>
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to django-users+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to django-users@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/CAHLKn70PDKYwv30LhTsRaQEJ5V9mwE0xri-EdmwPp8ZoAC5nng%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAHLKn70PDKYwv30LhTsRaQEJ5V9mwE0xri-EdmwPp8ZoAC5nng%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAPZR0N4xhpP0JLmFTQn_ogOztTAhj%2BKrP2kF-9DkxXK3NxXq8A%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAPZR0N4xhpP0JLmFTQn_ogOztTAhj%2BKrP2kF-9DkxXK3NxXq8A%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHLKn70XcOkAWT-%2BgBpG-m6Agh65AVXfU%3DsErY8iSvUF9Y0iaA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAHLKn70XcOkAWT-%2BgBpG-m6Agh65AVXfU%3DsErY8iSvUF9Y0iaA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPZR0N6s5WGH6KPU3mt7QnH%2B2QsC0t1CsaZHixXt%2B1ifzW2d2A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to