0

I have apps Users and Projects and would like to define another app called Roles for extending django-auth for per-project basis.

I defined ProjectMembership in the Roles app as a custom ManyToMany relationship model. But how can I define the M2M field in User or Project model with through declaration?

So question is can we define model's field from another app?

4

2 回答 2

1

I don't think it is possible, and even if it is possible then it is in my opinion a very bad solution.

I think your best option is to create the ProjectMembership model with two FK's, one to User and one to Project. Then you have a manual M2M relation, and you only can't use all nice Django features for working with M2M relations.

If you however want this features (they aren't needed) then you should modify either the User or the Project model.

于 2010-07-02T08:51:10.350 回答
1

是的,你可以,django 会自动为你创建反向关系。用related_name它来命名!

修改(金钱修补)User模型不是一个好主意。如果要扩展它,请通过以下方式进行:

于 2010-07-02T09:30:37.247 回答