如何从数据库中将现有值获取到django admin的django模型字段中

时间:2018-11-28 12:12:10

标签: django django-models django-admin

我需要帮助,以将question_name模型类中的现有问题从字段dependent_question放入字段Questions(带下拉列表)。当用户从Django管理面板添加任何新问题时,它将帮助用户选择相关问题。

# model.py 
class Questions(models.Model):
question_id = models.AutoField(primary_key=True)
question_name = models.CharField(max_length=300)
dependent_question = models.CharField(max_length=300,blank=True, null=True) 

1 个答案:

答案 0 :(得分:0)

看看这篇文章:https://simpleisbetterthancomplex.com/tutorial/2018/01/29/how-to-implement-dependent-or-chained-dropdown-list-with-django.html

它向您展示了如何使用javascript实现。我已经做到了,而且效果很好。