Re: Modifying Django's User Model
Thanks for the info. I'll check it out. On Jun 12, 11:06 am, Rajesh Dwrote: > On Jun 12, 9:29 am, LeeRisq wrote: > > > I am interested in changing the primary key of the User model to email > > and also use that as the username. > > > I would like to maintain the admin interface as well. > > > I am uncertain about the ramifications of doing this. I understand > > this change will need to be reflected in other models and some views, > > but does anyone know just how deep this change would need to go? > > If you're mainly interested in making the email field unique (rather > than a PK), you could use a custom user-creation form of your own. In > your form, ensure that the clean_email method rejects duplicate > emails. If you create users through admin, unregister the built-in > UserAdmin class and reregister your own UserAdmin class that uses your > custom user-creation form. > > If you want to allow login by email instead of by username, here's a > starting point: > > http://www.djangosnippets.org/snippets/74/ > > -Rajesh D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Modifying Django's User Model
On Jun 12, 9:29 am, LeeRisqwrote: > I am interested in changing the primary key of the User model to email > and also use that as the username. > > I would like to maintain the admin interface as well. > > I am uncertain about the ramifications of doing this. I understand > this change will need to be reflected in other models and some views, > but does anyone know just how deep this change would need to go? If you're mainly interested in making the email field unique (rather than a PK), you could use a custom user-creation form of your own. In your form, ensure that the clean_email method rejects duplicate emails. If you create users through admin, unregister the built-in UserAdmin class and reregister your own UserAdmin class that uses your custom user-creation form. If you want to allow login by email instead of by username, here's a starting point: http://www.djangosnippets.org/snippets/74/ -Rajesh D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Modifying Django's User Model
I am interested in changing the primary key of the User model to email and also use that as the username. I would like to maintain the admin interface as well. I am uncertain about the ramifications of doing this. I understand this change will need to be reflected in other models and some views, but does anyone know just how deep this change would need to go? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Modifying the User model
That's the workaround we were about to implement. But what I was searching for, was a more consistent way to modify the **model** itself (which will be reflected into the database structure and consequently in the forms), not the way Django handles the forms. I think Django choice isn't so silly, as we have to remember it is a general purpose user class (in some applications you won't even need email adress). Thanks anyway for your help ;) Davide On Apr 10, 8:12 pm, soniiicwrote: > The way I achieved this was to make my own registration form and use > this: > > email = forms.EmailField(widget=forms.TextInput(attrs=dict > (attrs_dict,maxlength=75)),label=_(u'Email address')) > > where attrs_dict was earlier defined as: > attrs_dict = { 'class': 'required' } > > also, the email address isn't checked for uniqueness (which i think is > silly) so I added this: > > def clean_email(self): > """ > Validate that the email is not already in use. > > """ > try: > user = > User.objects.get(email__iexact=self.cleaned_data['email']) > except User.DoesNotExist: > return self.cleaned_data['email'] > raise forms.ValidationError(_(u'This email is already taken. > Please > choose another.')) > > On Apr 10, 6:51 pm, Davide wrote: > > > > > Hi all, > > we've been using the django User model from contrib.auth.models > > As we want to re-use as much code as possible, is there a way to edit > > the class properties, making the "email" field required? As a default > > this is not a required field. Gooogled for some answers but didn't > > find one, but if I missed something please let me know. > > Thanks in advance, > > Davide --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Modifying the User model
The way I achieved this was to make my own registration form and use this: email = forms.EmailField(widget=forms.TextInput(attrs=dict (attrs_dict,maxlength=75)),label=_(u'Email address')) where attrs_dict was earlier defined as: attrs_dict = { 'class': 'required' } also, the email address isn't checked for uniqueness (which i think is silly) so I added this: def clean_email(self): """ Validate that the email is not already in use. """ try: user = User.objects.get(email__iexact=self.cleaned_data['email']) except User.DoesNotExist: return self.cleaned_data['email'] raise forms.ValidationError(_(u'This email is already taken. Please choose another.')) On Apr 10, 6:51 pm, Davidewrote: > Hi all, > we've been using the django User model from contrib.auth.models > As we want to re-use as much code as possible, is there a way to edit > the class properties, making the "email" field required? As a default > this is not a required field. Gooogled for some answers but didn't > find one, but if I missed something please let me know. > Thanks in advance, > Davide --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Modifying the User model
Hi all, we've been using the django User model from contrib.auth.models As we want to re-use as much code as possible, is there a way to edit the class properties, making the "email" field required? As a default this is not a required field. Gooogled for some answers but didn't find one, but if I missed something please let me know. Thanks in advance, Davide --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---