Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

Yes you can, django will automatically create the reverse relation for you. Use related_name to give it a name!

Modifying (money patching) the User model isn't a good idea. If you want to extend it, do it either via:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top