django admin “create user” and “change user” doesn't work

21 views
Skip to first unread message

Kasra Khosravi

unread,
May 10, 2015, 8:49:57 AM5/10/15
to django...@googlegroups.com
I'm writing a simple django contact form. I have defined my models.py and admin.py in the following manner :

models.py :

    from django.db import models
    from django.contrib.auth.models import User
    
    class Contact(models.Model):
    ACTIVE = 1
    PENDING = 2
    SUSPENDED = 3
    INACTIVE = 4
    STATUS_CHOICES = [
        (ACTIVE, 'Active'),
        (PENDING, 'Pending'),
        (SUSPENDED, 'Suspended'),
        (INACTIVE, 'Inactive'),
    ]
    status = models.IntegerField(choices=STATUS_CHOICES, default=ACTIVE)
    user = models.OneToOneField(User, null=True)
    name = models.CharField(max_length=200)
    title = models.CharField(max_length=200)
    company = models.CharField(max_length=200)
    description = models.CharField(max_length=200)
    tags = models.CharField(max_length=200, null=True)
    email = models.CharField(max_length=200, null=True)
    mobile = models.CharField(max_length=11, null=True)
    mailing_street = models.CharField(max_length=200, null=True)
    mailing_city = models.CharField(max_length=200, null=True)
    mailing_state = models.CharField(max_length=200, null=True)
    mailing_country = models.CharField(max_length=200, null=True)
    mailing_zipcode = models.CharField(max_length=200, null=True)

    def __str__(self):
        return self.name

admin.py :

    from django.contrib import admin
    from django.contrib.auth.admin import UserAdmin
    from django.contrib.auth.models import User
    from .models import Contact

    class ContactInline(admin.StackedInline):
        model = Contact

    class UserAdmin(UserAdmin):
        inlines = [ContactInline]

    admin.site.unregister(User)
    admin.site.register(User, UserAdmin)

    
The problem is that when I click on "Add User" in django admin, it shows me the user fields so I can create a user but when I click on "save", it shows me an error like this :

The webpage is not available, ERR_CONNECTION_RESET

I have deleted this section of the code and then I was able to save the user but I need this part.

    ACTIVE = 1
    PENDING = 2
    SUSPENDED = 3
    INACTIVE = 4
    STATUS_CHOICES = [
        (ACTIVE, 'Active'),
        (PENDING, 'Pending'),
        (SUSPENDED, 'Suspended'),
        (INACTIVE, 'Inactive'),
    ]
    status = models.IntegerField(choices=STATUS_CHOICES, default=ACTIVE)

Any idea how I can solve this problem?

Reply all
Reply to author
Forward
0 new messages