user.groups.add(group) or group.user_set.add(user), Which is better and why ? or difference between them

jzz

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.

knbk

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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

adduser,addgroup“正在使用的组”

组对象没有属性 user_set

唯一约束失败:groups_groupmember.group_id、groups_groupmember.user_id

运行addgroup / adduser。获取:Option s模棱两可(shell,系统)错误

user.groups.add(组)或group.user_set.add(用户),哪一个更好,为什么?或他们之间的差异

为什么该组不在 user_set 中显示其用户(它包含 test02)?

“ groups”和“ groups $ USER”显示不同的组(缺少拨号)

终端中的`groups $ USER`和`groups'有什么区别?

If I do not understand the difference in stability between Debian stable and Debian testing, am I better off with Debian testing?

auth.User.groups :(字段E304)“ User.groups”的反向访问器与“ UserManage.groups”的反向访问器冲突

查找不属于USER或GROUP的文件

Addgroup:找不到命令

Lubuntu的Adduser

挂载的文件系统上的set-user-ID和set-group-ID位(suid与nosuid选项)的不确定状态?

Facebook图形-可以检查用户是否是不带user_groups的组的成员?

如何在Django中通过User.groups.through添加字段?

user_managed_groups的Facebook Access令牌类型(应用程序或用户)

根据某些group_name过滤ForeignKey(user)模型

docker run --user和--group-add参数之间的区别

例如,如何更改“User.group(:age).count”的输出?

安全的Apache PHP安装:使用正确的user:group

使用查找来查找不属于USER或GROUP的文件

如何使用 Group By 和 Join 访问对象 User (django admin)?

sql group by user HAVING time ASC ORDER BY time DESC

如何扩展Django Group并仍在Django User中使用

Adding a user to sudo group vs creating a sudoers file

在Laravel 4中使用Auth :: User()-> user_group-> name打印用户组名称

Difference between mail and mailx?

Difference between nohup, disown and &