[英]Django delete confirmation view displaying variable name instead of information
Can anyone help me with the following scenario?任何人都可以帮助我解决以下情况吗? I have 3 tables like bellow.
我有 3 张像下面这样的桌子。 1 & 2 is my data tables.
1 & 2 是我的数据表。 And 3 keeps the relationship with 1 & 2.
并且 3 保持与 1 & 2 的关系。
1.Qa table
-------------
|ID | QA |
-------------
|1 |qa1 |
|2 |qa2 |
|3 |qa3 |
-------------
a field of my Qa model
tags = select2.fields.ManyToManyField(Tag, blank=True, verbose_name='Tag')
2.Tag table
-------------
|ID | Tag |
-------------
|1 |tag1 |
|2 |tag2 |
|3 |tag3 |
-------------
3.qa tag relation
---------------------
|ID |QA_ID |Tag_ID |
---------------------
|1 |1 |2 |
|2 |1 |3 |
|3 |2 |1 |
|4 |3 |1 |
|5 |3 |2 |
|6 |3 |3 |
---------------------
Edit
编辑
qa model质量保证模型
class Qa(models.Model):
question_text = models.CharField(max_length=1000, verbose_name='Question')
tags = select2.fields.ManyToManyField(Tag, blank=True, verbose_name='Tag')
"""
And some more fields.
"""
def __str__(self):
return self.question_text
class Meta:
ordering = ("id",)
verbose_name = 'QA data'
tag model标签模型
class Tag(models.Model):
tag_text = models.CharField(max_length=30, unique=True, verbose_name='Tag')
def __str__(self):
return self.tag_text
class Meta:
verbose_name = 'QA Tag'
※I do not have qa_tag model ※没有qa_tag型号
If I delete the list of Tag (from above 2.Tag Table), it redirects to the confirmation table.如果我删除标签列表(从上面的 2.Tag 表),它会重定向到确认表。 And it displays the list with some variable name like bellow
并显示带有一些变量名称的列表,如下所示
what I really expect is (something user readable information)我真正期望的是(用户可读的信息)
I cannot figure out why this happens and how to fix it.我无法弄清楚为什么会发生这种情况以及如何解决它。 Any help would be much appreciated.
任何帮助将非常感激。
Edit2:
编辑2:
After Daniel Roseman's Answer I tried to create an own model to handle the many to many relation在 Daniel Roseman 的回答之后,我尝试创建一个自己的模型来处理多对多关系
class Qa_Tag(models.Model):
def __str__(self):
return self.tag.tag_text
And the qa model changed as below并且 qa 模型更改如下
class Qa(models.Model):
....
tags = select2.fields.ManyToManyField(Tag, blank=True, through = 'Qa_Tag', verbose_name='Tag')
....
It shows the values when deleting.它显示删除时的值。 But my I had to register Qa_Tag in admin.py and only way I could assign the relation is though Qa_Tag view.
但是我必须在 admin.py 中注册 Qa_Tag 并且我可以分配关系的唯一方法是通过 Qa_Tag 视图。
Now I know the reason is there is no __str__()
method for my Qa_Tag table but still couldn't figure out how to write a model class for generated qa_tag table without braking anything.现在我知道原因是我的 Qa_Tag 表没有
__str__()
方法,但仍然无法弄清楚如何在不制动任何东西的情况下为生成的 qa_tag 表编写模型类。
您没有展示您的模型,但几乎可以肯定您没有在 Qa_tags 类上定义__str__
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.