I have a model where I have the following architecture
- There is Post model
- And there is an answer model for the given post (just like in stack overflow)
Since there are some fields which I do not want the user to populate, I have made a custom form for both of the models. The custom form class is working absolute for the first model i.e. Post Model, but I am getting this strange for the PostAns model. If I remove the class PostAnsForm then it works fine.
class PostAns(models.Model):
created = models.DateTimeField(auto_now_add=True)
creator = models.ForeignKey(User, blank=True, null=True)
post = models.ForeignKey(Post)
body = models.TextField()
like_count = models.IntegerField(default=0,blank=True,null=True)
# If we use markdown can remove this if not
body_html = models.TextField(blank=True)
class PostAnsForm(ModelForm):
class Meta:
model = PostAns
fields = ('body')
I haven’t found a similar error on the net.
the
fieldsattribute is expecting a list or tuple. it finds a string, which is also iterable, but iterating through a string yields each character.try
this is a fairly common case, and the exact error depends on your string, so is hard to google. the hint is the list of fields (did you possibly change the order of the characters?)
notice how they are all one character, and spell out what looks like a string value from your code