tags:

views:

16

answers:

2

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?

+1  A: 

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.

muksie
A: 

Yes you can, django witl 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 inheritance (http://scottbarnham.com/blog/2008/08/21/extending-the-django-user-model-with-inheritance/), or use a profile through a 1:1 relationship (which is the recommended way by django (http://sam.bluwiki.com/blog/2008/05/extending-user-model-profiles-in-django.php).

lazerscience