Insert data into multiple models

67 views
Skip to first unread message

Mukul Mantosh

unread,
Oct 23, 2017, 8:45:49 AM10/23/17
to Django users
I have two models (User and Employee). I want to create a new user and make a reference between employee and user. 


User Table
1. Name
2. E-Mail
3. Date of Birth
4. Contact Number


Employee Table
1. EmployeeID
2. Address 
3. Country
4. Profile Photo
5. user_id

Problem Statement:  When i create a new user then automatically it should create a new record in employee table with user_id referencing to the user table and without writing two SQL Statements and should also follow the database transaction property(ACID).


mohammad k

unread,
Oct 23, 2017, 12:53:47 PM10/23/17
to django...@googlegroups.com
you can use model signals 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/124695ae-e1f1-4252-8bbb-272cb438243b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mohammad k

unread,
Oct 23, 2017, 12:59:08 PM10/23/17
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages