I have a Django model, which is essentially a list of words. It is very simple and is defined as follows:
class Word(models.Model):
word = models.CharField(max_length=100)
I need the particular word as a string object. (I am replacing all the characters in the word with asterisks for a simple Hangman game.) However, I cannot seem to get the word as a string object.
I tried adding this method to the Word class, but that did not seem to work either.
def __str__(self):
return str(self.word)
I get an empty string object instead of the word.
What do I need to do to get the value of the CharField as a string object? Thanks for your help.
Edit: The weird thing for me is that it has no problem returning an integer. For example, if I were do do something like this:
word = Word(pk=2821)
print word.id
... it would print 2821, the id of that particular record.