Reputation: 665
when I try to extend the django admin user. I got the following error.
can only concatenate tuple (not "str") to tuple
this is my models.py class
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
User.add_to_class('age', models.BooleanField(default=False))
class Employee(models.Model):
user=models.OneToOneField(User)
name=models.CharField(max_length=100)
address=models.CharField(max_length=200)
designation=models.CharField(max_length=100)
email=models.CharField(max_length=100)
role=models.CharField(max_length=10)
project=models.CharField(max_length=50)
task=models.CharField(max_length=50)
avatar = models.ImageField("Profile Pic", upload_to="images/", blank=True, null=True)
def __unicode__(self):
return self.name
def ensure_profile_exists(sender, **kwargs):
if kwargs.get('created', False):
Employee.objects.create(user=kwargs.get('instance'))
post_save.connect(ensure_profile_exists, sender=User)
this is my admin.py file
from django.contrib.auth.admin import UserAdmin
UserAdmin.list_display += ('age')
UserAdmin.list_filter += ('age')
UserAdmin.fieldsets += ('age',)
I need to add one filed called age to the django admin user, for example first name ,last name ,email and age in personal info. please someone help me.
Upvotes: 1
Views: 6038
Reputation: 53336
Change these lines to have comma after 'age'
UserAdmin.list_display += ('age')
UserAdmin.list_filter += ('age')
as
UserAdmin.list_display += ('age',)
UserAdmin.list_filter += ('age',)
Otherwise python evaluates ('age')
to 'age'
rather than tupple.
You have done this appropriately in third line UserAdmin.fieldsets += ('age',)
Upvotes: 3