Wednesday, May 27, 2015

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

Think I got it now. 
Can you see if this stackoverflow answer solves your problem:

On Wed, May 27, 2015 at 9:41 AM, Felipe <unehub@gmail.com> wrote:
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.



--
  
Filipe Ximenes
+55 (81) 8245-9204
Vinta Software Studio
http://www.vinta.com.br

--
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/CAA-QWB2eS2ajrVYs2O7EpKcovkHKo0yOAKLeYYbR9uAfu%3Dq%2BnQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment