Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9192511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:56:31+00:00 2026-06-17T20:56:31+00:00

I am currently learning Django though the Django-book tutorial and I’ve come across an

  • 0

I am currently learning Django though the Django-book tutorial and I’ve come across an error.
On chapter 5 I am supposed to input this in the python interpreter

    >>> p1 = Publisher.objects.create(name='Apress', 
    ... address='2855 Telegraph Avenue', 
    ... city='Berkeley', state_province='CA', country='U.S.A.', 
    ... website='http://www.apress.com/') 
    >>> p2 = Publisher.objects.create(name="O'Reilly", 
    ... address='10 Fawcett St.', city='Cambridge', 
    ... state_province='MA', country='U.S.A.', 
    ... website='http://www.oreilly.com/') 
    >>> publisher_list = Publisher.objects.all() 
    >>> publisher_list 

According to the tutorial, I should get an output of

    [<Publisher: Publisher object>, <Publisher: Publisher object>] 

However I get the same output but with 4 objects!!

    [<Publisher: Publisher object>, <Publisher: Publisher object>, <Publisher: Publisher object>, <Publisher: Publisher object>] 

Also I am supposed to change my models.py to this (added unicode functions) from django.db import models

    class Publisher(models.Model): 
    name = models.CharField(max_length=30) 
    address = models.CharField(max_length=50) 
    city = models.CharField(max_length=60) 
    state_province = models.CharField(max_length=30) 
    country = models.CharField(max_length=50) 
    website = models.URLField() 

    def __unicode__(self): 
            return self.name 

    class Author(models.Model): 
    first_name = models.CharField(max_length=30) 
    last_name = models.CharField(max_length=40) 
    email = models.EmailField() 

    def __unicode__(self): 
            return u'%s %s' % (self.first_name, self.last_name) 

    class Book(models.Model): 
    title = models.CharField(max_length=100) 
    authors = models.ManyToManyField(Author) 
    publisher = models.ForeignKey(Publisher) 
    publication_date = models.DateField() 

    def __unicode__(self): 
            return self.title 

In order to display the objects. Here is the output according to the tutorial

    >>> from books.models import Publisher 
    >>> publisher_list = Publisher.objects.all() 
    >>> publisher_list 
    [<Publisher: Apress>, <Publisher: O'Reilly>] 

But I’m still getting

    [<Publisher: Publisher object>, <Publisher: Publisher object>, <Publisher: Publisher object>, <Publisher: Publisher object>] 

Not sure why I’m getting more objects and why I cannot view the outputs of the unicode…

Thank you for your help!

**http://django-book.readthedocs.org/en/latest/chapter05.html is the link to the specific chapter!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:56:32+00:00Added an answer on June 17, 2026 at 8:56 pm

    Try this sample:

    models.py

    class Debt(models.Model):
        user = models.ForeignKey(User)
        name = models.CharField(max_length=50,
            help_text="Name to identify your debt.")
        due_day = models.PositiveSmallIntegerField(
            help_text="Day of the month payment is due.")
    
        def __unicode__(self):
            return "{0}".format(self.user)
    

    views.py

    def debt(request):
    
    return render(request, 'debt.html', {
        'debts': Debt.objects.filter(),
    }) 
    

    debt.html

     {% for debt in debts %}
         {{debt.user}} - {{debt.name}} <br/>
     {% endfor %}  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Been stuck on this for ages. Currently learning Django and done some bits on
I'm currently learning about cube mapping, I found this tutorial: http://www.keithlantz.net/2011/10/lighting-and-environment-mapping-with-glsl/ He transform normal
As I'm currently learning Django / Python, I've not really been using the concept
In the process of learning Django and Python. I can't make sense of this.
I'm currently learning about pickling in Python and I'm confused with an error I'm
Folder Structure I'm currently learning Django from the Django book. I have the following
im currently learning python (in the very begining), so I still have some doubts
I am currently learning backbone.js via a screencast tutorial, somewhere along the way, my
Hi I'm currently learning Python since the syntax feels so succinct and the idioms
I'm currently learning about concurrency in C++ and came across using a vector of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.