Re: Digest for satchmo-users@googlegroups.com - 1 Message in 1 Topic

21 views
Skip to first unread message

Andrea de la Huerta

unread,
Sep 17, 2012, 12:38:35 PM9/17/12
to satchm...@googlegroups.com
Hi,

I wouldn't do it with tags.

The first reason: they use generic relations so it can be sometimes more complex to make things work the same as with "normal" relations. But the main reason for me to avoid using tags in your case would be, that it would be very difficult to group your attributes, like Material: gold, silver, .... Colors: red, green, ... , etc. And lets say use something like a filter-box or something based on this goups.

I think a more flexible and still very easy approach would be to use a model for each attribute-group, like:

class Color(models.Model):
    product = models.ManyToManyField(Product, blank=True, null=True)
    name = models.CharField(_("Name"), max_length=30)
    slug = models.SlugField(...)
   
So this way you can filter your products on a selected color like:

Product.objects.filter(color__slug==myslug)

You can integrate this Attributes on the admin Product-page adding an inline to the object

For integrating this new attributes on the admin's product page, look at my answer (username = andzep) on stackoverflow:

http://stackoverflow.com/questions/4920358/filter-products-by-attribute

regards
Andrea


On 17.09.2012 16:44, satchm...@googlegroups.com wrote:

Group: http://groups.google.com/group/satchmo-users/topics

    Josue Balandrano <xir...@gmail.com> Sep 16 12:16PM -0700  

    Hi, I'm building a webstore. I am going to sell Jewelry here, so the thing
    is that I have my main categories like "earrings, necklaces" and so on. But
    I need some attributes like "Material, color, stone, size". But these can't
    be Options because not every product is available in all colors or all
    sizes and I don't fell comfortable with attributes because I need a way to
    list all this attributes and be able to filter the result as per attribute
    selected.
    So I was thinking about installing Django-tagging, it seemes this is more
    or less what I need. The only problem is if I am going to be able to have a
    tree like distribution for my tagging? and do I have to modify the product
    models in order to implement the tagging?
    Thank you in advance.

     

You received this message because you are subscribed to the Google Group satchmo-users.
You can post via email.
To unsubscribe from this group, send an empty message.
For more options, visit this group.

--
You received this message because you are subscribed to the Google Groups "Satchmo users" group.
To post to this group, send email to satchm...@googlegroups.com.
To unsubscribe from this group, send email to satchmo-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/satchmo-users?hl=en.

--
----
Metamorfosys GbR
Guttenthau 6 
95469 Speichersdorf 
   
T: +49 9648 913 594
F: +49 9648 913 643
in...@metamorfosys.de 
www.metamorfosys.de 

Geschäftsführung: Andrea de la Huerta u. Dominik Klüter
Gerichtsstand: Ansbach m. Außenst.

-------------------------------------------------------------------------
-------------------------------------------------------------------------
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte
Informationen. Wenn Sie nicht der richtige Adressat sind oder diese
E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den
Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie
die unbefugte Weitergabe dieser Mail ist nicht gestattet.
-------------------------------------------------------------------------
This e-mail may contain confidential and/or privileged information. If
you are not the intended recipient (or have received this e-mail in
error) please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material  in
this e-mail is strictly forbidden.
-------------------------------------------------------------------------
-------------------------------------------------------------------------

Josue Balandrano

unread,
Sep 18, 2012, 11:14:28 AM9/18/12
to satchm...@googlegroups.com, in...@metamorfosys.de
Actually, something like that is what I was thinking last night while fliping through the pages of my Django Book.
I was thinking about using the Attributes model that Satchmo allready has, just to make it easier for future updates and so.
Then creating the values throught the python shell or raw SQL statements, so I would have Attribute.Name=Color, Attrubte.Values=[white,black,golden, [etc...]]
Then creating custom validations for this attributes which will not let the staff user to add more values than the values that allready exists in the DB. This way the staff user could only choose between the values that I allready populated (or any other admin user that know what he/she is doing).
This way I'm only going to have to create some views in order to retrieve this Attrbutes to display them the way I want. Something like doing a search of the attributes giving an array with the slugs and sorting them by Value, grouping the same value, and then by Attribute Name. This way I can create a list like this:
{% retrieve_special_atts "[custom slug a rray]" as Attributes %}
<ul>
 <li>
    {% for atname in Attributes %}
    {{ Attributes.Name }}
         <ul>
             {% for value in Attributes.values %}
              <li> {{value.name}} </li>
              {%endfor%}
         </ul>
      {%endfor%}
 </li>
</ul
This is not finished, because I will also need this not to be a list but a form. So every Attribute Value would be a checkbox, and whenever a user ticks any of the attribute values would call a filtering function wich would read the category that the user allready is in and the get data which will have the attribute filter values and fitler the products accordingly.

Andrea de la Huerta

unread,
Sep 18, 2012, 12:49:54 PM9/18/12
to Josue Balandrano, satchm...@googlegroups.com
Hi,

that with the Attributes might be a good Idea. I went another way, as I wanted to have and define my new Product-Attributes totally independently from the Django-Core. (This allows for custom model-methods, adding all you need for the attributes (description, pictures, etc.) and so on without troubling my mind with overriding any other models. If you don't need any of that, it might be a good idea to use the attributes. Still, I think you're seeing some things a little bit more complicated than they actually are:


On 18.09.2012 17:14, Josue Balandrano wrote:
Actually, something like that is what I was thinking last night while fliping through the pages of my Django Book.
I was thinking about using the Attributes model that Satchmo allready has, just to make it easier for future updates and so.
With my approach you shouldn't touch the core-code at all, so updates wouldn't be an issue. You should create all these new Model-Classes on a local-app in your project, something like:

satchmoproject/store/localsite/prodattributes/models.py

There you create a Model for each Group: Color, Material, etc. As I already posted.

and on:  satchmoproject/localsite/prodattributes/admin.py  ... you add the part for the inlines. And if you want to, you can also add each model too, to batch edit attributes, etc.


Then creating the values throught the python shell or raw SQL statements, so I would have Attribute.Name=Color, Attrubte.Values=[white,black,golden, [etc...]]
Then creating custom validations for this attributes which will not let the staff user to add more values than the values that allready exists in the DB. This way the staff user could only choose between the values that I allready populated (or any other admin user that know what he/she is doing).
About the user-restriction to change/delete/create attributes, well you probably can adjust permissions for a group of users (the normal users) to not to be able to change, add, delete anything in the prodattributes-app. And the admins can still use the admin for managing these. I'm not 100% sure if this users would still be able to select the inline attributes on the product-pages or not, but if that's no problem, then this would be the easiest way of achieving this.

This way I'm only going to have to create some views in order to retrieve this Attrbutes to display them the way I want. Something like doing a search of the attributes giving an array with the slugs and sorting them by Value, grouping the same value, and then by Attribute Name. This way I can create a list like this:
{% retrieve_special_atts "[custom slug a rray]" as Attributes %}
<ul>
 <li>
    {% for atname in Attributes %}
    {{ Attributes.Name }}
         <ul>
             {% for value in Attributes.values %}
              <li> {{value.name}} </li>
              {%endfor%}
         </ul>
      {%endfor%}
 </li>
</ul
This is not finished, because I will also need this not to be a list but a form. So every Attribute Value would be a checkbox, and whenever a user ticks any of the attribute values would call a filtering function wich would read the category that the user allready is in and the get data which will have the attribute filter values and fitler the products accordingly.

yes, that's something similar to what I did. I implemented a box on the right side-bar to filter products based on the selected checkboxes (without Ajax though... on my version the user needs to press an "apply" button).  You can use context-processors to set the filter-settings "globally" and adjust your views/templates for the category listings and search to use this filter-settings in case they are set.

Regards,
Andrea

Josue Balandrano

unread,
Sep 18, 2012, 12:59:07 PM9/18/12
to satchm...@googlegroups.com, in...@metamorfosys.de
I think you are right. It would be easier to create my own local-app. I am going to try that. And yes, my idea was to create some context-processors which are going to grab de variables from the GET data that the form is going to yell. This is just in an attempt to remove the "apply" o "refresh" button. Less click, people are lazy :p
Thank a lot!


El lunes, 17 de septiembre de 2012 11:38:47 UTC-5, adlh escribió:

Andrea de la Huerta

unread,
Sep 18, 2012, 1:19:34 PM9/18/12
to Josue Balandrano, satchm...@googlegroups.com
Oh, and just one more advice: you can also use the forms.ModelMultipleChoiceField to nicely spit-out a checkbox for each "option" on the Model in a "field", without having to hard-code anything. I also ended up using a custom widget for this field (overriding the CheckboxSelectMultiple), in order to easily modify the markup of each checkbox AND to put a mini-icon beside the checkboxes (from the model's image) instead of text... a really DRY and fast way to generate this filter-forms.... and for colors, you could even use the slug as a class to define the background of a transparent image or so... it just makes fun thinking about all this possibilities ;-)

Josue Balandrano

unread,
Sep 18, 2012, 1:23:54 PM9/18/12
to satchm...@googlegroups.com, Josue Balandrano, in...@metamorfosys.de
Yes, that is what I was thinking. Apparently we think alike :p.
May I wask the url to the webstore that you were refering to? just to check it out?

Andrea de la Huerta

unread,
Sep 18, 2012, 1:47:07 PM9/18/12
to Josue Balandrano, satchm...@googlegroups.com
it's a spanish site... but the box "Búsqueda avanzada" on the right is hard to miss :-)
www.dinamo-papeleria.es

Josue Balandrano

unread,
Sep 18, 2012, 1:54:20 PM9/18/12
to satchm...@googlegroups.com, Josue Balandrano, in...@metamorfosys.de
No worries, I'm from Mexico. Really nice work there!
Reply all
Reply to author
Forward
0 new messages