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

  • SEARCH
  • Home
  • 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 7862477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:08:33+00:00 2026-06-02T23:08:33+00:00

I bit confuse with __unicode__() in django. I’m still a newbie. I have this

  • 0

I bit confuse with __unicode__() in django. I’m still a newbie.

I have this code:

models.py

class Order(models.Model):
    order_num = models.IntegerField(verbose_name="OR Number")
    order_date = models.DateTimeField(auto_now_add=True,verbose_name="OR Date")
    customer = models.ForeignKey(User)

    def __unicode__(self):
        return self.order_num

I register it on the admin side. When I tried to add order it has an error:

TypeError at /admin/store/order/add/
coercing to Unicode: need string or buffer, int found

What will I declare on the method __unicode__(self)?

It is clear I don’t have string on my fields. How can I declare buffer?

or

Anyone has another answer.. please help.. Thanks.

  • 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-02T23:08:34+00:00Added an answer on June 2, 2026 at 11:08 pm

    __unicode__ needs to return a unicode object.

    The error you see is because only string or buffer-protocol objects can be automatically converted (it’s still better to explicitly convert them).

    For built-in Python types, or any user-defined class that has its own __unicode__ method, you can just call unicode on them:

    def __unicode__(self):
        return unicode(self.order_num)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: Django models sometimes confuse the heck out of me. I have the following
I'm still a bit confused on models and saving data, perhaps someone could help
i have this example found here: http://threedubmedia.com/code/event/drag/demo/resize2 and i tried to reproduce it in
I am little bit confuse about log4j in grails. I need to log info
Bit confused here, I have an on-demand instance but do I get charged even
I'm a bit confused why I can't initialize a getter this way: @synthesize stack
I'm getting a bit confuse with the rails console. I'm trying to connect to
the question title might be a bit confuse. but here is my case. i
--I haven't develop any iPhone Web Application ever...so i am little bit confuse about
I have no clue how to phrase this question in a search engine. I'm

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.