Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#16156 closed Bug (invalid)

Django overrides user-defined "User" model with its own

Reported by: dloewenherz@… Owned by: nobody
Component: contrib.auth Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm getting some very weird results when I name my model "User".

Here's the definition.

from django.db import models

class User(models.Model):
    email = models.EmailField()
    password = models.CharField(max_length=51)
    birthday = models.DateField()
    gender = models.BooleanField() # True => Male

Here's the ModelForm:

from django import forms

class RegistrationForm(forms.ModelForm):
    class Meta():
        model = User
        fields = ['email', 'password']
        widgets = {
                'email': forms.TextInput(attrs={'autocomplete': 'off'}),
                'password': forms.PasswordInput(attrs={'autocomplete': 'off'}) }

When I render this form in my template with "{{ form.as_p }}" I see the following help text for the password input: "Use '[algo]$[salt]$[hexdigest]' or use the change password form.".

Seems as though there is some weird override of the Django-defined User model and mine.

Change History (2)

comment:1 by Karen Tracey, 13 years ago

Resolution: invalid
Status: newclosed

I'd guess you are importing Django's User somewhere before you specify the model User in the meta class for your RegistrationForm. I do not see what you are describing, using your model, and avoiding any import of User from `django.contrib.auth.models':

>>> from ttt.models import User
>>> import datetime
>>> User.objects.create(email="xyz@xyz.com", password="uhoh", birthday=datetime.date.today(), gender=True)
<User: User object>
>>> u = User.objects.all()[0]
>>> u
<User: User object>
>>> u.email
u'xyz@xyz.com'
>>> from django import forms
>>> class RegistrationForm(forms.ModelForm):
...     class Meta():
...       model = User
...       fields = ['email', 'password']
...       widgets = {
...               'email': forms.TextInput(attrs={'autocomplete': 'off'}),
...               'password': forms.PasswordInput(attrs={'autocomplete': 'off'})}
... 
>>> rf = RegistrationForm(instance=u)
>>> rf.as_p()
u'<p><label for="id_email">Email:</label> <input name="email" value="xyz@xyz.com" autocomplete="off" maxlength="75" type="text" id="id_email" /></p>\n<p><label for="id_password">Password:</label> <input autocomplete="off" id="id_password" type="password" name="password" maxlength="51" /></p>'
>>> 
Version 0, edited 13 years ago by Karen Tracey (next)

comment:2 by anonymous, 13 years ago

I actually just figured it out (I think). Without thinking, I put this all in an app called auth. I think that threw off the namespacing with the built-in Django auth, which I have in INSTALLED_APPS and I am using for the admin.

Note: See TracTickets for help on using tickets.
Back to Top