7π
I found this snippet when reading a duplicate question to this one. Also check this code:
class UserForm( forms.ModelForm ):
class Meta:
model= User
exclude= ('email',)
username = forms.EmailField(max_length=64,
help_text = "The person's email address.")
def clean_email( self ):
email= self.cleaned_data['username']
return email
class UserAdmin( admin.ModelAdmin ):
form= UserForm
list_display = ( 'email', 'first_name', 'last_name', 'is_staff' )
list_filter = ( 'is_staff', )
search_fields = ( 'email', )
admin.site.unregister( User )
admin.site.register( User, UserAdmin )
Neither answer is originally mine. Up vote on the other thread to the owners for the karma boost. I just copied them here to make this thread as complete as possible.
5π
Check out this snippet, and read the comments for updates.
For the form, why not just inherit from (or directly use) the auth login form. See django/contrib/auth/forms.py
- Why does Django Queryset say: TypeError: Complex aggregates require an alias?
- RuntimeError: Never call result.get() within a task Celery
- How do you raise a python exception and include additional data for Sentry?
3π
Please see the below link which illustrates the way in which we should solve the problem.
http://groups.google.com/group/django-users/browse_thread/thread/c943ede66e6807c
- Django β specify database for TestCase fixtures
- Making Django Readonly ForeignKey Field in Admin Render as a Link
1π
Sounds like you can just mask the username with the word βemailβ and all the usernames will just have the email show up instead.
-1π
Unless I missed something, the solution should be really simple; just make a normal form with a text field and a password field. When the HTTP request method is POST, try to fetch the user with the given e-mail address. If such a user doesnβt exist, you have an error. If the user does exist, try to authenticate the user and log her in.
- Django drf simple-jwt authentication"detail": "No active account found with the given credentials"
- Apps aren't loaded yet exception occurs when using multi-processing in Django
- Django form.is_valid() always false
- Enable PK based filtering in Django Graphene Relay while retaining Global IDs
- Run Django tests in the VSCode Test explorer?