I am trying to extend django.contrib.auth and came accross adding a user into a group, which can be done in 2 ways. I was just wondering why is it like so, and what are the advantages of one over the other.
They do the exact same thing.
A many-to-many relation consists of an intermediate table with a foreign key to both models. user.groups.add(group)
will create an entry in that table where the foreign keys point to the user
and group
instances. The same happens with group.user_set.add(user)
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句