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 8497335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:05:53+00:00 2026-06-11T00:05:53+00:00

I am following a lightbird tutorial on creating a forum with Django/Python. Here is

  • 0

I am following a lightbird tutorial on creating a forum with Django/Python. Here is the code to create a Thread model.

class Thread(models.Model):
    title = models.CharField(max_length=100)
    created = models.DateTimeField(auto_now_add=True)
    creator = models.ForeignKey(User, blank=True, null=True)
    modified = models.DateTimeField(auto_now=True)
    forum = models.ForeignKey(Forum)

    def __unicode__(self):
        return unicode(self.creator) + " - " + self.title

And a Post model:

class Post(models.Model):
    title = models.CharField(max_length=60)
    created = models.DateTimeField(auto_now_add=True)
    creator = models.ForeignKey(User, blank=True, null=True)
    thread = models.ForeignKey(Thread)
    body = models.TextField(max_length=10000)

    def __unicode__(self):
        return u"%s - %s - %s" % (self.creator, self.thread, self.title)

    def short(self):
        return u"%s - %s\n%s" % (self.creator, self.title, self.created.strftime("%b %d, %I:%M %p"))
    short.allow_tags = True

I am having difficulty understanding the code after the unicode function! I have been using the unicode while creating model in a very simple form like:

class Post(models.Model):
    title = models.CharField(max_length=100)

    def __unicode__(self):
        return self.title

I understand this but not the code in the models above. Could someone please explain it to me. Thank you!

  • 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-11T00:05:54+00:00Added an answer on June 11, 2026 at 12:05 am
     unicode(self.creator) +\ #will call the __unicode__ method of the User class
     ' - ' +\ # will add a dash
     self.title #will add the title which is a string
    

    then for the second one

      "%s"%some_var #will convert some_var to a string (call __str__ usually...may fall back on __unicode__ or something)
    

    so

    return u"%s - %s\n%s" % (self.creator, self.title, self.created.strftime("%b %d, %I:%M %p"))
    

    will call the __str__ (or maybe __unicode__)function on User class for the creator

    then it adds a dash and the title

    \n is an end line

    and strftime will convert a timestamp into english “MonthAbbrv. Day, 24Hr:Minutes”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm following the django tutorial at Django by example in http://www.lightbird.net/ . In the
Following code worked fine abstract class FunctionRunnable<V> implements Runnable { protected abstract V calculate();
Following leads in this thread and others, I've set up a code block where
following code is used to find url from a string with php. Here is
Following is my code: <table border=0 align=center cellpadding=0 cellspacing=0 class=grid_table> <tr class=grid_caption><td class=grid_caption>Customer Name</td></tr>
following piece of code: class a{ public function __get($key) { if($key == 'obj') {
I'm following this tutorial (http://lightbird.net/dbe/cal1.html) to build a calendar app, but I can't get
Following code produces a nested array as a result for keys containing three items:
Following code takes like 2500 milliseconds on an i7-*3.4 GHz windows-7 64-bit computer to
Following chunk html code works as expected: <iframe src=http://www.amazon.com/></iframe> But when trying embed inner

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.