1

I have a model with data in it defined like this:

class SyncJob(models.Model):
  date = models.DateTimeField()
  user = models.ForeignKey(User, unique=False)
  source = models.CharField(max_length=3, choices=FS_CHOICES)
  destination = models.CharField(max_length=3, choices=FS_CHOICES)
  options = models.CharField(max_length=10, choices=OPTIONS)

  def _unicode_(self):
    return u'%s %s %s' % (self.date, self.source, self.destination)

And I have a view to retrieve data:

def retrieve(request):
  sync = SyncJob.objects.get(id=02)
  return render_to_response('base.html', {'sync': sync})

But when rendering the page I only get: SyncJob object Instead of getting the date, source and destination info. How can I make it so I get this data?

1
  • Also it should be __unicode__ not _unicode_. Commented Aug 16, 2010 at 21:09

1 Answer 1

2

Watch the naming of special methods:

def _unicode_(self):
    ...

should be:

def __unicode__(self):
    ...

Python special methods have two underscores on each end of the name.

Sign up to request clarification or add additional context in comments.

1 Comment

+1 for the fast catch, this is an easy mistake for people new to django/python because when reading text __ is so easy to confuse with _.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.