Hi Ezequeil,
Thanks for the explanation! This worked, but defining a new widget from scratch
meant that I lost the other helpful attributes (length, class etc.) that the
admin adds for me. Instead, in the DRY spirit, I opted to just add this one
extra attribute. Here's the relevant code:
class MyAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['username'].widget.attrs['autocomplete'] = 'off'
Erik
> Den 12. nov. 2015 kl. 13.33 skrev Ezequiel Bertti <[email protected]>:
>
>
> In html:
>
> <input type="email" name="email" autocomplete="off">
>
> Um django you need to create a form for your model and set a field to
> username. In this field, set a widget like this:
>
> username = forms.CharField(widget=forms.TextInput(attrs={'autocomplete':
> 'off'}))
>
> Now you set a form on your model admin, like this example
>
> https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#adding-custom-validation-to-the-admin
>
>
> On Thu, Nov 12, 2015 at 8:46 AM, Erik Cederstrand <[email protected]>
> wrote:
> Hello,
>
> I have a model with a CharField named "username". When I edit a model
> instance in the admin, my browser likes to autocomplete the contents of the
> "username" field with my username for the Django site, regardless of what was
> entered previously.
>
> Is there anything I can do to disable this behaviour, except for renaming the
> field to "username_PLEASE_DONT_AUTOCOMPLETE_SAFARI_IM_LOOKING_AT_YOU"?
>
> Thanks,
> Erik
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/DFF8D42F-D4F1-4686-942E-A906F919488B%40cederstrand.dk.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> Ezequiel Bertti
> E-Mail: [email protected]
> Cel: (21) 99188-4860
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/CACrQMYrb9aDDD1L%2BFvOtn90M6YDEuaVODoO-JWPqF0E5YiS9UA%40mail.gmail.com.
> 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 [email protected].
To post to this group, send email to [email protected].
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/B74769F9-9905-4998-AF98-2461854321C1%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.