I have a list of model objects:
just an example (I'm not really doing a list of all()):
class Tag(models.Model):
name = models.CharField(max_length=50,primary_key=True)
#Some other fields....
def __str__(self):
return self.name
mylist = list(Tag.objects.all())
What's the best way of converting this to a list of strings ?
Do I have to iterate the list ?
I was doing something like:
newList = [ t.str() for t in mylist ]
Any better way ?
__str__or__unicode__method so you do not need to pass them strings. You could also do [x.name for x in mylist], that may be a little faster.