开发者

django forms from two tables referencial integrity

i have a class named cv,and a class named universit开发者_高级运维y, and each user that completes his cv, should choose a University he studyes at.

My problem is: one student can study at one or 2 or three universities, or may be a user that is not student.

I need to take this data into a form, and i use ModelForm. The data from the Cv class, and from the University class in the same form, and the user can add one or more universities, or no university. (in the same form)

How should i do it? Should i use ModelForm? if i have a foreign key in the CV class, and the user is not a student (so he is at zero universities), i may get an referencial integrity error.

thanks a lot


ModelForms will display your ManyToManyFields (that's the correct type for your university field in your Cv class) as multipe-select widget.

If you prefer checkboxes, use the forms.CheckboxSelectMultiple widget for this field in your form class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜