了解 Django Auth 应用程序如何创建其表

Understanding how the Django Auth app creates its tables

models.py file of the Django auth app 中,有 usergroup 的模型在数据库中创建它们各自的 table:

没有 class user_groups,但幕后发生了一些奇妙的事情,还创建了一个 table auth_user_groups 来跟踪哪些用户属于哪些组。 (每行包含一个 user_idgroup_id)。

谁能帮我理解这是怎么发生的?我可能想在我自己的应用程序中复制此功能,我将 customer 模型与 group_id.

相关联

用户和组共享多对多关系。

参见: https://docs.djangoproject.com/en/2.1/topics/db/examples/many_to_many/

groups

Many-to-many relationship to Group

https://docs.djangoproject.com/en/2.1/ref/contrib/auth/#django.contrib.auth.models.User.groups