How do I construct a Django form with model objects in a Select widget?

后端 未结 2 1927
自闭症患者
自闭症患者 2021-01-08 00:41

Let\'s say I\'m using the Django Site model:

class Site(models.Model):
    name = models.CharField(max_length=50)

My Site values are (key,

2条回答
  •  不要未来只要你来
    2021-01-08 01:02

    I think you're looking for ModelChoiceField.

    UPDATE: Especially note the queryset argument. In the view that is backing the page, you can change the QuerySet you provide based on whatever criteria you care about.

提交回复
热议问题