Hello All,
Hopefully a really simple one, possible even stupid!
I'm building a tagging system in Django and would like to allow spaces and other characters in the tag name for display but filter them out and use lower case when matching names etc.
To that end I have added a field to my Tag model as so:
class Tag(models.Model):
name = models.CharField(max_length=200, unique=True)
matchname = re.sub("\W+" , "", name.lower())
However I am running into a problem, the CharField is not a string and I cannot for the life of me find out how to convert it to one!
Any help (plus comments on the general approach) would be much appreciated!
Thanks,
Dave
Edit: Great answers one and all. Have marked Dave Webb's as it explains the main thing I was doing wrong, Doh! Although I will be using Ferran's answer as it makes sense to be able to use Djangos built in querys on the matchname, plus it means I can make both unique to ensure no repeats with different caps etc.
Thanks guys, if I could mark all as answers I would as they are all valid and potentially useful for others in the same situation. Up votes all round!
(also should I leave this here or add another post for it?)