Reputation: 11
I'm writing a blog program using django.
class Tag(models.Model):
name = models.CharField(max_length=100)
class BlogPost(models.Model):
.....
tags = models.ManyToManyField(Tag)
....
In django's admin, the tag field in BlogPost displays as a <select>
How I can make it display like a <input type="text"/>
? and the Tag is automatically added when new tag is inputed.
Thanks.
Upvotes: 1
Views: 208
Reputation: 304
Create your own widget class which inherits from the forms.Widget. Override "render" method which converts tag objects to strings. When you save form data can use the "clean" method of tag field. Sorry for my English. Good example you can see in django-taggit third-party application https://github.com/alex/django-taggit/blob/master/taggit/forms.py
Upvotes: 1