更新时间:2023-02-12 08:37:50
我刚发现:
self.fields['project'].choices = [('', '----------')] + [(p.id, p.name) for p in Project.objects.all()]
在RecordForm的 init 中也可以做到这一点.但是@Peter DeGlopper在评论中的答案更好.
In the init of the RecordForm also does the trick. But @Peter DeGlopper answer in the comments is better.