django UserAdmin

76 views
Skip to first unread message

Sachin Tiwari

unread,
Oct 7, 2014, 4:46:53 AM10/7/14
to django...@googlegroups.com
Hi,

I added an extra field phone number in existiing user model and now I tyring to access that field by below method,

 UserAdmin.list_display = ('email', 'first_name', 'last_name','is_staff', SMSRegistration.phone_no)

type object 'SMSRegistration' has no attribute 'phone_no'

Please help.


Collin Anderson

unread,
Oct 7, 2014, 12:41:04 PM10/7/14
to django...@googlegroups.com
Would something like this work?

class UserAdmin(admin.ModelAdmin):
    list_display
= ('email', 'first_name', 'last_name','is_staff', 'phone_no')

   
def phone_no(self, user):
       
return user.smsregistration.phone_no


Sachin Tiwari

unread,
Oct 8, 2014, 5:42:50 AM10/8/14
to django...@googlegroups.com
Hi Collin,

Thanks for your kind support,

I tried follwing ways but it did not work,

 class UserAdmin(UserAdmin):
    inlines = (EmployeeInline, )
    #UserAdmin.list_display = ('email', 'first_name', 'last_name','is_staff',SMSRegistration.phone_no)
    list_display = ('email', 'first_name', 'last_name','is_staff','phone_no')
    #list_display = ('email', 'first_name', 'last_name','is_staff','phone_no')
    #list_display = UserAdmin.list_display + ('phone_no',)

    def phone_no(self, SMSRegistration):
        #return User.SMSRegistration.phone_no
        return SMSRegistration.phone_no

If I used below line, It will show smsregistration option but phone number would not be dispalyed.
UserAdmin.list_display = ('email', 'first_name', 'last_name','is_staff',SMSRegistration)

I am sharing my smsregistartion class also,

class SMSRegistration(models.Model):
    user = models.OneToOneField(User)
    phone_no = models.IntegerField(max_length=10,blank=False,null=False)
   

Sachin Tiwari

unread,
Oct 8, 2014, 6:42:44 AM10/8/14
to django...@googlegroups.com


On Tuesday, October 7, 2014 2:16:53 PM UTC+5:30, Sachin Tiwari wrote:

Collin Anderson

unread,
Oct 8, 2014, 8:20:28 AM10/8/14
to django...@googlegroups.com
What happens with my code? Did you try the lowercase version of user.smsregistration.phone_no and putting the string "phone_no" in list_display?

Sachin Tiwari

unread,
Oct 8, 2014, 9:03:30 AM10/8/14
to django...@googlegroups.com
 Hi Collin,

It gives same type of error.

Collin Anderson

unread,
Oct 8, 2014, 9:31:11 AM10/8/14
to django...@googlegroups.com
It gives same type of error.

Interesting. What did the error say? 

Sachin Tiwari

unread,
Oct 8, 2014, 11:03:01 PM10/8/14
to django...@googlegroups.com
Hi Collin,

Thanks, I did some mistake, its working. 
Reply all
Reply to author
Forward
0 new messages