admin shows `model name` object instead of values for foreign key fields

13 views
Skip to first unread message

Larry Martell

unread,
Feb 6, 2015, 8:30:02 PM2/6/15
to django...@googlegroups.com
I have a 1.7 app, and in admin when I reference a foreign key field, instead of showing the values in the drop down, it shows "`model name` object":

Inline image 2
This does not happen in 1.5 (in a different app). 

Here are my models:

class IPGroups(models.Model):
    groupName = models.CharField(max_length=20)
    
class AllowedIPs(models.Model): 
    ip = models.CharField(max_length=15)
    group = models.ForeignKey(IPGroups)

Here is my admin code:

class IPGroupsAdmin(admin.ModelAdmin):
    list_display = ('groupName',)
    list_filter = ('groupName',)
admin.site.register(IPGroups, IPGroupsAdmin)
    
class AllowedIPsAdmin(admin.ModelAdmin): 
    list_display = ('ip', 'group')
    list_filter = ('ip', 'group')
admin.site.register(AllowedIPs, AllowedIPsAdmin)

How can I get it show the values from the IPGroups table? I'm sure I'm doing something simple and stupid wrong, but I can't see it.

Thanks!

Daniel Roseman

unread,
Feb 6, 2015, 9:06:13 PM2/6/15
to django...@googlegroups.com
On Friday, 6 February 2015 20:30:02 UTC, Larry....@gmail.com wrote:
I have a 1.7 app, and in admin when I reference a foreign key field, instead of showing the values in the drop down, it shows "`model name` object":

 
How can I get it show the values from the IPGroups table? I'm sure I'm doing something simple and stupid wrong, but I can't see it.

Thanks!

You haven't defined a `__unicode__` method (or `__str__` on Python3) on the IPGroups model..
--
DR.

Larry Martell

unread,
Feb 6, 2015, 9:16:21 PM2/6/15
to django...@googlegroups.com
Thank you very much Daniel.  

Reply all
Reply to author
Forward
0 new messages