> You'll add it inside your Poll class, maybe you should first read a
> python tutorial, it'll be helpful,
> good luck
>
> class Choice(models.Model):
> question = models.CharField(maxlength=200)
> pub_date = models.DateTimeField('date published')
> def __str__(self):
> return self.choice
you'll want to make sure this returns an actual field of your
model :) I suspect it was just a copy&paste issue, but for the
new developer, this can be confusing. I think you meant
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(maxlength=200)
votes = models.IntegerField()
def __str__(self):
return self.choice # return the "choice" field as
# the string representation
Any python expression that returns a string can be used as the
return-value of the __str__() function, so you can do more
complex things, but I'd avoid binding your string representation
to HTML, as it's too easy to implement bogus ideas like
class Person(models.Model):
# ... implementation
def __str__(self):
return "<b>%s, %s</b> (%i)" % (
self.last_name,
self.first_name,
self.age,
)
so don't put HTML in your strings, because otherwise, if you want
to use the str() function in CSV output, you'll end up with HTML
in your CSV file.
-tim
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---