views:

66

answers:

2

i have a class named cv,and a class named university, 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

+1  A: 

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.

mawimawi
thanks a lot, i'll try and post the final version :)
dana
A: 

ok, i'm using a ManyToManyField,and it seems quite logical. But what if i cannot create a list with all the Universities in the world so that the user can choose from the list one or two he is attending at.

What if i want to create dinamically the list, from what the users insert in a textfield.. The default django behaviour is a drop down list, can i add an text field alternative to my many to many relation form field between a users and universities? Thanks

dana
If you want to use some text field which auto-suggests something, you have to use some sort of Ajax stuff. There is a nice jquery plugin which handles this kind of problem: http://code.drewwilson.com/entry/autosuggest-jquery-plugin Hope that helps.
mawimawi
that's interesting, i'll try it! thanks!
dana