views:

44

answers:

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  A: 

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.

pmalmsten
+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 _.
marr75
Thanks for the tip!
xzased