Check the bottom of tutorial #1 - Wait a minute. <Poll: Poll object> is, utterly, an unhelpful representation of this object. Let's fix that by editing the polls model (in the polls/models.py file) and adding a __unicode__()<https://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.__unicode__> method to both Poll and Choice:
class Poll(models.Model): # ... def __unicode__(self): return self.question class Choice(models.Model): # ... def __unicode__(self): return self.choice It's important to add __unicode__()<https://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.__unicode__> methods to your models, not only for your own sanity when dealing with the interactive prompt, but also because objects' representations are used throughout Django's automatically-generated admin. Mark On Tue, Apr 10, 2012 at 9:46 PM, oneroler <samuel.ha...@gmail.com> wrote: > I'm working through the tutorial and was setting up the admin site for the > polls app. I noticed in the "Select Poll to Change" section that it was > showing "poll object" rather than "what's up" or the question associated > with the poll. Same is true on the Choice area of admin, the dropdown for > polls just shows a number of poll objects rather than the names. I can't > seem to find a difference in my code versus the tutorial. Below is my > code. Any help would be appreciated. > > *mysite/polls/admin.py* > from polls.models import Poll, Choice > from django.contrib import admin > > class PollAdmin(admin.ModelAdmin): > fieldsets = [ > (None, {'fields': ['question']}), > ('Date information', {'fields': ['pub_date'], 'classes': > ['collapse']}), > ] > > admin.site.register(Poll, PollAdmin) > admin.site.register(Choice) > > *mysite/polls/models.py* > from django.db import models > > class Poll(models.Model): > question = models.CharField(max_length=200) > pub_date = models.DateTimeField('date published') > > class Choice(models.Model): > poll = models.ForeignKey(Poll) > choice = models.CharField(max_length=200) > votes = models.IntegerField()* > > mysite/settings.py* (just the changed text) > DATABASES = { > 'default': { > 'ENGINE': 'django.db.backends.sqlite3', # Add > 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. > 'NAME': > '/Users/Sam/dev/django/mysite/mysite1.sqlite', # Or > path to database file if using sqlite3. > 'USER': '', # Not used with sqlite3. > 'PASSWORD': '', # Not used with sqlite3. > 'HOST': '', # Set to empty string for > localhost. Not used with sqlite3. > 'PORT': '', # Set to empty string for > default. Not used with sqlite3. > } > } > > INSTALLED_APPS = ( > 'django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.sites', > 'django.contrib.messages', > 'django.contrib.staticfiles', > # Uncomment the next line to enable the admin: > 'django.contrib.admin', > # Uncomment the next line to enable admin documentation: > # 'django.contrib.admindocs', > 'polls', > ) > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/django-users/-/2-CC0B8PXvYJ. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.