|
Posted by IM NS |
|
|
I am filling my form with initial data using the normal:
form = somethingForm(initial = {
'title' : something.title,
'category' : something.category_id,
})
The title works fine, but if the category is a ModelChoiceField and a ForeignKey in the model, the initial data won't work. Nothing will be selected in the Select Box. If I change category to an IntegerField in the model it works fine. I still want to use a ForeignKey for category though, so how do I fix this? |
|
|
Posted by Herbert Poul ![]() |
|
|
have you tried directly referring to the model, instead of it's id? something like: 'category': something.category SCT - http://sct.sphene.net |
|
|
Posted by IM NS |
|
|
Hey Herbert
Thanks for the input, but that didn't work. |
|
|
Posted by IM NS |
|
|
I posted this question on stackoverflow too and somebody said I should do something like this
form = somethingForm(initial = {
'title' : something.title,
'category' : [("database value","display value")],
})
but that didn't work either. I ended up just not using django forms for the category and doing it all manually ... checking the post data instead of the form.clean_data. I know it's not the best, but I can't find a solution for this problem, so it will have to do. |



