If the crispy form is using the usual render methods of Django you can
subclass the Select class (in forms/widgets.py), reimplement the
"render_option" method and add the parameter to the returned HTML, then you
can set the widget attribute of the form field to your created class.

I don't know whether django crispy forms provides a better alternative

On Mon, Dec 15, 2014 at 2:26 PM, Jonathan Dan <j....@student.tudelft.nl>
wrote:
>
> Hello,
>
> I have two models:
>
>      class Currency(models.Model):
>         ...
>         available = models.BooleanField()
>
>      class Offer(models.Model):
>         ...
>         currency = models.ForeignKey('Currency')
>
> I make a form from the Offer model:
>
>      class OfferForm(ModelForm):
>         class Meta:
>            model = Offer
>
> How can I add an attribute tag with the value `currency.available` to
> each `<option>` from the `<select>` `Currency` widget?
>
> (I am also open to solutions using external apps (like
> django-crispy-forms))
>
> (This question has also been asked on stackoverflow:
> http://stackoverflow.com/q/27474719/1011154 )
>
> Best regards
> Jonathan Dan
>
> --
> 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+unsubscr...@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/548F19D8.7010101%40student.tudelft.nl.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@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/CALn3ei0%3DM-TrnZRGByPMXjHxH_YcRY2hGip%2BWLer70%2Bbs%2B8Wag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to