It is required to make a filter on the similarity of this .
In Oscar, as far as I know, this is not the case (and most likely in the public domain too). I was a little concerned about this, and decided that it is worth taking the method of sorting products that uses Oscar (from A to Z, by rating, etc.) source -pastebin.com/jC0NRVCC, and slightly alter it to the attributes of goods. But I can't figure out how to inherit these attributes for an array.

SORT_BY_MAP = { #CustomsType:Here Are Properties TOP_RATED: '-rating', TITLE_A_TO_Z: 'title_s', TITLE_Z_TO_A: '-title_s', } 

We need to take the main Attributes class - then i.imgur.com/dwzlucW.png?1 what am I talking about (in order to base the search in the right way)? Or take all the products that returns a search query, and have to somehow work with them.

The problem is that Django and Oscar are new to me, and I don’t really understand all this complex structure.

Please help me with this problem, I have been suffering for several days already! Thank!

  • @ Well, who will help? Or too complicated question? - LighFusion
  • about sorting - try this option in views.py where you get data from the database: - CLASS_MODEL - the name of your model - field - the name of the field / fields - by which to sort CLASS_MODEL.objects.all (). order_by (* field) - ascending CLASS_MODEL.objects.all (). order_by (* field) - descending - ivan K.
  • @ivanK. - sorting is not very suitable for me, I found where the filter (search) is used for Solr - but again, the structure there is almost the same as in Sort_by_map. And I can't understand what it means - `OSCAR_SEARCH_FACETS = {'fields': OrderedDict ([(' product_class', {'name': _ ('Type'), 'field': 'product_class'}), (' rating ', {' name ': _ (' Rating '),' field ':' rating '}), `more precisely I don’t really understand why product_class is taken first here , not [from here] ( goo.gl/ov01bE ) , how do I then specify the product_class from AbstractProductAttribute? - LighFusion
  • I tried to do something like `('product.attr.size', {'name': _ ('Size'), 'field': 'small'}),` but I understand it is not that - LighFusion
  • @ivanK. will you help? Can I drop the classes I need - on PasteBin, if that helps? - LighFusion

1 answer 1

Tax is small - an update, I almost managed to achieve the desired effect. The result is that the product is now filtered by attribute options, but the problem is that - the form that is used - not suitable for displaying options - attribute values, in fact, instead of options - should be either 3 CheckBox 'a or 1 DropDown Menu (with 3 selection options), that is, Small Medium Large, and there instead Option. Actually the code itself - can someone come in handy!

  product_class = indexes.MultiValueField(null=True, faceted=True) 

.

  def prepare_product_class(self, obj): attributes = obj.attributes.all() if len(attributes) > 0: return [product_class.type for product_class in attributes] 

And the actual value that can be substituted into the product_class .:

  class Meta: model = ProductAttribute fields = ["name", "code", "type", "option_group", "required"] 

It is important to update the indexes! - the result is almost the same in principle, the value is Size. Small, Medium, Large does not display, as I understand it in view of the fact that there is no necessary form of a button - in HayStack, but how to make it is not very clear? - help no one wants to finish the topic =)? Or create a separate question on the forms?