Re: [mezzanine-users] cartridge list all products

2021-05-31 Thread ek ekke
Oh wow thanks guys

On Saturday, 29 May 2021 at 00:16:18 UTC+1 mol...@gmail.com wrote:

> On 29/05/2021 1:28 am, Ken Bolton wrote:
>
>
>
> On Fri, May 28, 2021 at 4:56 AM ek ekke  wrote:
>
>> I am trying to list all products from cartridge, is that function all 
>> ready in there and how can i call it from a template? 
>> Don't want to write the view if it's all ready in there somewhere.
>>
>
> Check out the `Category` module, which is a subclass of Mezzanine's `Page`.
>
> Simplest way is 
>
> Product.objects.all()
>
> To get that in a template, you might need to write a template tag, e.g. I 
> added something to my Orders Change List template so that I could filter 
> orders by a specific product (and export the results to CSV). The basics 
> are:
>
> In admin.py (or forms.py):
>
> def get_all_products():
> return [(p.id, p.title) for p in 
> Product.objects.all().order_by('title')]
>
> class OrderByProductForm(forms.Form):
> product = forms.ChoiceField(label="Export filtered orders containing",
> choices=[])
>
> def __init__(self, *args, **kwargs):
> super(OrderByProductForm, self).__init__(*args, **kwargs)
> self.fields["product"].widget = 
> forms.Select(choices=get_all_products())
> templatetags/myapp_tags.py: 
>
> @register.simple_tag
> def export_order_by_product_form(request):
> querystring = request.GET.dict()
> return OrderByProductForm(queries=querystring)
>
> And then in templates/admin/order_change_list.html:
>
> {% extends "admin/change_list.html" %}
> {% load admin_urls myapp_tags %}
>
> {% block object-tools-items %}
>
> 
>{% export_order_by_product_form request %}
>
> 
> {{ block.super }}
> {% endblock %}
>
> Note then i have also defined a view for "order_export" which uses the 
> selected Form item to find the right orders and export them to CSV.
>
> Hope this helps.
>
> Seeya. Danny.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mezzanine-users/de3266af-fda5-45a4-aa9c-a2dbfcb3886fn%40googlegroups.com.


Re: [mezzanine-users] cartridge list all products

2021-05-28 Thread Danny

On 29/05/2021 1:28 am, Ken Bolton wrote:



On Fri, May 28, 2021 at 4:56 AM ek ekke > wrote:


I am trying to list all products from cartridge, is that function
all ready in there and how can i call it from a template?
Don't want to write the view if it's all ready in there somewhere.


Check out the `Category` module, which is a subclass of Mezzanine's 
`Page`.


Simplest way is

Product.objects.all()

To get that in a template, you might need to write a template tag, e.g. 
I added something to my Orders Change List template so that I could 
filter orders by a specific product (and export the results to CSV). The 
basics are:


In admin.py (or forms.py):

def get_all_products():
    return [(p.id, p.title) for p in 
Product.objects.all().order_by('title')]


class OrderByProductForm(forms.Form):
    product = forms.ChoiceField(label="Export filtered orders containing",
    choices=[])

    def __init__(self, *args, **kwargs):
    super(OrderByProductForm, self).__init__(*args, **kwargs)
    self.fields["product"].widget = 
forms.Select(choices=get_all_products())


templatetags/myapp_tags.py:

@register.simple_tag
def export_order_by_product_form(request):
    querystring = request.GET.dict()
    return OrderByProductForm(queries=querystring)

And then in templates/admin/order_change_list.html:

{% extends "admin/change_list.html" %}
{% load admin_urls myapp_tags %}

{% block object-tools-items %}


   {% export_order_by_product_form request %}
   

{{ block.super }}
{% endblock %}

Note then i have also defined a view for "order_export" which uses the 
selected Form item to find the right orders and export them to CSV.


Hope this helps.

Seeya. Danny.


--
You received this message because you are subscribed to the Google Groups "Mezzanine 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mezzanine-users/08b321ba-261e-dea9-1866-c4d9dcdd84f1%40gmail.com.


Re: [mezzanine-users] cartridge list all products

2021-05-28 Thread Ken Bolton
On Fri, May 28, 2021 at 4:56 AM ek ekke  wrote:

> I am trying to list all products from cartridge, is that function all
> ready in there and how can i call it from a template?
> Don't want to write the view if it's all ready in there somewhere.
>

Check out the `Category` module, which is a subclass of Mezzanine's `Page`.

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mezzanine-users/CAN7ek0PjPAQ%3D9-LhZiww9ntMWNq0uty69Ask%3DGp%2BZqqUcB%2Bgyw%40mail.gmail.com.


[mezzanine-users] cartridge list all products

2021-05-28 Thread ek ekke
I am trying to list all products from cartridge, is that function all ready 
in there and how can i call it from a template?
Don't want to write the view if it's all ready in there somewhere.

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mezzanine-users/cd3623f0-5cc4-4749-924b-78df4cae6d6an%40googlegroups.com.