In a django app I am writing,I have created a MyEntry and MyCategory ,and given unicode() implementations for them.To represent an entry ,I am using a string built from an entry's category name,starttime and entry's creation date.
However ,when I try to list the entries,I am getting
['category1']13:02:542011-07-16
['category2','category3']18:21:342011-07-11
['category3']18:09:192011-07-11
This [] comes from the list comprehension I guess. I wish I could get the names like
category2,category3-18:21:34-2011-07-11
category3-18:09:19-2011-07-11
How should I implement unicode() for my models to get this effect? Can someone help?
My models are
from datetime import date
class MyCategory(models.Model):
name=models.CharField(unique=True,max_length=50)
...
def __unicode__(self):
return self.name
class MyEntry(models.Model):
today=models.DateField(default=date.today)
starttime=models.TimeField(null=True)
categories=models.ManyToManyField(MyCategory)
...
def __unicode__(self):
return "%s%s%s"%([str(x.name) for x in self.categories.all()],self.starttime,self.today)