multiple INSERT with django form

83 views
Skip to first unread message

thol...@gmail.com

unread,
May 6, 2016, 12:20:03 PM5/6/16
to Django users
Hi

I'm trying to create a django form based on the model. The model contains fields: username, date, shift, department, team. Team and Department are defined in different app and are extending the user through UserProfile. I would like to have a table that is generated automatically based on the number of days in the month and users from department and look more less like that:

xxxxx | Day1   | Day2   | Day3   | ... | Day31   |
--------------------------------------------------
User1 | Shift1 | Shift2 | Shift3 | ... | Shift31 |
--------------------------------------------------
User2 | Shift1 | Shift2 | Shift3 | ... | Shift31 |
--------------------------------------------------
User3 | Shift1 | Shift2 | Shift3 | ... | Shift31 |

where user (is a private key of another table) and day values will be added during the generation of the table and shift will be the dropdown box.

INSERT to the database should be constructed for each day (user1, day1, shift1, department, team) where department and team should be taken automatically based on the username from UserProfile.

I do not know where to start. I've looked at django formset and it would seem a way to go but the formset is generating a HTML table code and all fields are from the form would be in the table. Additionally I would like the possibility to change the generated table within the same view.

I would be very grateful if you can point me to the documents that might help me.

Cheers,
Tom

Derek

unread,
May 9, 2016, 3:41:09 AM5/9/16
to Django users
You might want to consider using a jQuery plugin like appendGrid (http://appendgrid.apphb.com/); and then writing the necessary logic for the view that allows you to construct the grid and then process data from it (http://stackoverflow.com/questions/3670206/django-with-jquery-basic-help provides some clues).
Reply all
Reply to author
Forward
0 new messages