Does not work, why? remember, we need get each form inline.... guided on the next line
if you do this right, it will be a value equal to all forms, including doing this does not work takes the last forloop and entered.
I think this should be some kind or bug in Django, because should operate at the level of form, something like this.
El miércoles, 27 de mayo de 2015, 8:43:11 (UTC-5), Filipe Ximenes escribió:
-- self.initial = [{'attribute': attribute} for attribute in obj.category.attributes.all()]
# Important: This start each form with a different value, [{'attribute': 'Colors'}, {'attribute': 'Sizes'}, ..]
for choices in AttributeOptions.objects.filter(attribute=attribute): # This return 2 objects
self.fields['value_option'].queryset = choices # We thought at first sight that works, but what this does is take the last forloop.
I think this should be some kind or bug in Django, because should operate at the level of form, something like this.
self.fields.queryset = [{'value_option': choices1}, {'value_option': choices2} ... ]
We should open a ticket for this?
El miércoles, 27 de mayo de 2015, 8:43:11 (UTC-5), Filipe Ximenes escribió:
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 <une...@gmail.com> wrote:Hello, Filipe Ximenes, in 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 OptionInline 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 backendInline 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...@googlegroups.com .
To post to this group, send email to django...@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 --
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/36c6ac34-8b1c-4456-ab98-8fa667dff64e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment