Django orm: convert to linked tables?

0 like 0 dislike
5 views
There are 3 tables with a relationship, the standard User model:

class Place(models.Model): place = models.CharField() status = models.CharField() class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) place = models.ForeignKey(Place, on_delete=models.CASCADE) detail = models.CharField()


When registering a user you need to post and save data into appropriate tables. Actually a question how to do it immediately after receiving?
by | 5 views

2 Answers

0 like 0 dislike
In 2018 in Django to pass user data in two separate tables User and Profile is categorically wrong! Django already 4 years at least allows you to create your own User model with all the fields you need. This code will be much easier to write and maintain, and disappear the car and small truck JOINS s required for a reload Profile.

And in fact the issue: before saving the model instance in the database, create the associated models, as Django needs to know the primary key of the User to create them, and it is generated in the process of saving the model.

There is a package to work around this limitation: django-modelcluster, but in your case it's better to rewrite the user model.
by
0 like 0 dislike
AbstractBaseUser.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
asked Apr 12, 2019 by Egoraccountmail
110,608 questions
257,186 answers
0 comments
28,759 users