#32467: django admin widget.attrs not work with ForeignKey
-------------------------------------+-------------------------------------
     Reporter:  Hassan Igbaria       |                    Owner:  Hassan
         Type:                       |  Igbaria
  Cleanup/optimization               |                   Status:  closed
    Component:  Forms                |                  Version:  3.1
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by David Smith):

 * status:  assigned => closed
 * resolution:   => invalid


Comment:

 In your example, I think you should be using the `update` method rather
 than directly assigning a dict. There's a great example of this in the
 [https://docs.djangoproject.com/en/3.1/ref/forms/widgets/#styling-widget-
 instances docs].

 So I think your example should be:
 `self.fields['parent'].widget.attrs.update({'class': 'custom-class'})`

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32467#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.b1b0570e73bb0dfab794c9745d38318d%40djangoproject.com.

Reply via email to