Wednesday, May 27, 2015

Re: How to pass a queryset for each different field Admin Inlines

Hello, Filipe Ximenesin fact it is not so difficult. To avoid using ajax, what I do is initialize each form inline with a default value. Few ATTRIBUTES has verified and initialize no possibility that the fronentd they can edit. All right up here, but the problem is that for each attribute requires its respestivo initialized value, which is made by a queryset to each forminline initialized.

self.initial = [{'attribute': a} for a in obj.category.attributes.all()] # This initial attribute value, whit one for inline, Now need pass queryset a each value_option

If I have 10 ATTRIBUTES "obj.category.attributes.all", then initialize the form 10 form inlines no ability to edit and then "value_option" we pass your respestivos values with a queryset, "but the problem is that you have to spend a queryset" different "to each form inline"

Example form inlines 3, whit two fields, Attribute and Value Option
Inline 1 Values initial "Attribute": Colors and Value Option now requires queryset depending on its initial value, all this is built before loading the frontend, that is, that everything is done in the backend
Inline 2 Values initial "Attribute": Size .... "''"
Inline 3 Values initial "Attribute": Equipment .... ''''

 
El miércoles, 27 de mayo de 2015, 5:24:09 (UTC-5), Filipe Ximenes escribió:

From what I could understand, you want to change the options of the "value options" field depending on the selected "attribute".
Since the choosing of the "attribute" happens in the frontend and there's no page refresh, the backend does not know about it, and therefore cannot filter the "value options".
For this to work, you will need to write some javascript code to perform the filtering in the browser after the attribute is choosen.
It can also be achived with a ajax call.
Either way, not the easiest to do in django admin.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f782dcfe-f68b-4c92-b458-0724ff5fbb8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment