Re: Disable autocomplete in admin field

2015-11-13 Thread Erik Cederstrand

> Den 12. nov. 2015 kl. 14.41 skrev Erik Cederstrand 
> :
> 
> 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'

Just to follow up, this didn't actually work for me, I just thought so. 
Apparently, all major browsers have go to great lengths to ignore any attempts 
to disable autocomplete, and any suggestions to actually get it working 
involves hidden fields, custom javascript and all sorts of hoops and tricks 
(see e.g. 
http://stackoverflow.com/questions/22661977/disabling-safari-autofill-on-usernames-and-passwords).

So it seems I'm stuck with either disabling autocomplete entirely in my 
browser, or having the username for my LDAP server overwritten with 'erik' 
every time I open that form. Infuriating.

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 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/2A4E02D8-0813-4FA0-9804-BA1015C76472%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Disable autocomplete in admin field

2015-11-12 Thread Ezequiel Bertti
Great!

If you prefer to write some code and not implement new class. What you
thing to override the *get_form *method on model admin?

https://docs.djangoproject.com/en/1.8/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_form

def get_form(self, request, obj=None, **kwargs):
form = super(EmpresaAdmin, self).get_form(request, obj, **kwargs)
form.fields['username'].widget.attrs['autocomplete'] = 'off'
return form



On Thu, Nov 12, 2015 at 11:41 AM, Erik Cederstrand <
erik+li...@cederstrand.dk> wrote:

> 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 :
> >
> >
> > In html:
> >
> > 
> >
> > 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 <
> erik+li...@cederstrand.dk> 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 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/DFF8D42F-D4F1-4686-942E-A906F919488B%40cederstrand.dk
> .
> > For more options, visit https://groups.google.com/d/optout.
> >
> >
> >
> > --
> > Ezequiel Bertti
> > E-Mail: eber...@gmail.com
> > 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 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/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 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/B74769F9-9905-4998-AF98-2461854321C1%40cederstrand.dk
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Ezequiel Bertti
E-Mail: eber...@gmail.com
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 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/CACrQMYq36YQHB%3D%2BT-sqKbQ1hNMMOqJ4CBJHZj_Nmgp6DLq6a_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Disable autocomplete in admin field

2015-11-12 Thread Erik Cederstrand
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 :
> 
> 
> In html:
> 
> 
> 
> 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  
> 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 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/DFF8D42F-D4F1-4686-942E-A906F919488B%40cederstrand.dk.
> For more options, visit https://groups.google.com/d/optout.
> 
> 
> 
> -- 
> Ezequiel Bertti
> E-Mail: eber...@gmail.com
> 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 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/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 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/B74769F9-9905-4998-AF98-2461854321C1%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.


Re: Disable autocomplete in admin field

2015-11-12 Thread Ezequiel Bertti
In html:



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  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 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/DFF8D42F-D4F1-4686-942E-A906F919488B%40cederstrand.dk
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Ezequiel Bertti
E-Mail: eber...@gmail.com
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 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/CACrQMYrb9aDDD1L%2BFvOtn90M6YDEuaVODoO-JWPqF0E5YiS9UA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Disable autocomplete in admin field

2015-11-12 Thread Erik Cederstrand
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 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/DFF8D42F-D4F1-4686-942E-A906F919488B%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.