аватар question@mail.ru · 01.01.1970 03:00

Django Solr (Filter) - a falling list for objects, how to implement? or adapt

There is such a list of objects displayed by the value of the attributes of goods.

the values ​​of the attributes of goods that are interconnected - should be in the form of a drop -down SELECT (OPTION) list/dropdownMenu, i.e. - For example, instead of Size: Medium, Size: Small it should just be

  mediumsmall    

that these values ​​of the attributes are applied SIZE can be specified inside TemPlates (Label), i.e. This is not so important, the main thing is how they can be placed in this Select list (dropdown menu).


I want to add that I tried to change the values ​​that are indicated by the default, in TemPlates, instead of checkboxes - I tried to indicate Select Option, but the result was obtained Inappropriate

.


tamplates

browse.html:

  {%  for  field, Data  in  fact_data.items %}  { % ""> if> data.results %} r { % include  'search/partials/fact.html'   with  name = data.name items = data.ressults %}  { % endfor %}     

facet.html:

  { %  for  item  in  items %}  & lt; dd & gt;  & lt;  input   class  =  "" Facet_checkbox ""   type  =  name = " "{ithem.name }} "" /& gt;  & lt;  input   class  =   type  = 

аватар answer@mail.ru · 01.01.1970 03:00

Once, no one guessed how to realize it, he will have to explain himself. The values ​​that are formed in Haystack and processed in Template - are not adapted to the drop -down list as such, so these values ​​must be redirected to form, and in the form the logic is already described, for this you need to: 1. To make a special {tag}} which will receive values ​​from the dictionary and add it to TEMPLe, it will look like that -

  { % Load choice_tags %}     

in the tag itself you need to specify the form.

  @register.assignment_tag ()    def   choice_Form  ( request, field ):  form_class = adtochoiceform    

is a very important point when it comes to Django (OSCAR), I don’t know how to do where it is described, but OSCAR has a special UI.js, which describes the functions that convey values ​​from the field when the user pressed the form of choice, looks like this:

  O.Search.initfilterwidget (); initfilterwidget: function () { // auto-submit (hidden) Search Form When Selecting a) Option $ ( '#id_selected_Facets' ). ON ( 'chean' , function () { $ (this) .CLOSEST. class = ""> '> form' ). Submit (); }); }     

selection_Facets , these are the names of the field in your form, then it can be found in the code.

Next in Template should be conveying the values ​​from the dictionary.

  {%  for  field, Data  in  in  FACET_DATA.ITEMS %}  { %choice_FORM DATA Field  as  choice_form %}     

after you should specify the form with the form with the form to transmit the result to the target to the address string.

  & Lt; Form Method =   class  =  "" Form-Horizontal ""  & gt;  {% include  "" Partials/Form_fields.html ""   with  Form = Choice_Form %}  & Lt;/Form & Gt;     

Next, it is necessary to owe objects received from the dictionary to choice_tags and add them to the array (well, either to the dictionary or even immediately transfer to the form). This is done as I personally did as follows.

   for  dataesult  in  request [ 'Results' ]:  items.append (Dataresult)     

Well, we convey items, FILD to the adtoChoChoiceFORM Form = Form_class (ITEMS, FILD)

Next, you should create a class of the standard class, I will not fully describe the key parts to form for the formation List.

At the beginning we create an array choices = [] , into which we will transmit values ​​from the dictionary. Next, we hire objects. We tu to the objects of the key of interest to us, in my example this name and path of the URL.

   for  item  in  items: select_url = item.get ( 'select_url' ) class_name = item.get ( 'name' )     

and add our objects to the array. Here 1 is a very important point in order to avoid problems with repeated encoding in the URL, it is necessary to transcode all the characters in a simple view for this I used - the native library Django Purl

  choices.ppend ((unicode_unquote (seld_url), class_name))     

well, add our array to the chiocefield form - falling out - falling out List.

  Self.fields [ '' '"selection>' '">' '">' '">' '">' '">' '">' '">' '">' '">' '">' '">' '">' '">' '">' '">' '">' '">' " choices = choices, widget = forms.select (), label = _ ())     

and that’s all, I did not take into account the unicks (the heading line), since they are still themselves I decide, and in general, the method itself is not quite beautiful, and perhaps the form itself will need to be cleaned, because if the user chooses something else that remains in the form, and as a result the user doesn’t get what he wanted, but so far I have no time to finish everything.

If someone may have an option better I will be happy to hear! And so, unfortunately I decided myself!

Latest

Similar