开发者

django forms doubt

开发者 https://www.devze.com 2022-12-30 10:29 出处:网络
Here, I am a bit confused with forms in Django. I have information for the form(a poll i.e the poll question and options) coming from some db_table - table1 or say class1 in models. Now the vote from

Here, I am a bit confused with forms in Django. I have information for the form(a poll i.e the poll question and options) coming from some db_table - table1 or say class1 in models. Now the vote from this poll is to be captured which is anot开发者_如何学Cher model say class2. So, I am just getting confused with the whole flow of forms, here i think. How will the data be captured into the class2 table?

I was trying something like this.

def blah1()

    get_data_from_db_table_1()

    x = blah2Form()

    render_to_response(blah.html,{...})


Forms have nothing to do with models in Django. They are just class meant to get informations from a dictionary (often request.POST) and check if each data linked to a key match a type and a format (e.g: is this a string of the form "bla@foo.tld").

You can ask django to create a form from a model, and in that case it will do its checking job, then if the data match, it will create a model, fill it and save it.

If a form is not created from a model, it will do nothing but checking. It will save nothing.

If it is created from a model, it will create a new instance of this particular model instance and save it.

If you want something more complicated, like, pre fill a form from various models or according to some conditions, or, say, you need to save several models according to the result of one form, you must do it manually.

0

精彩评论

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

关注公众号