Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed_by field with through model(that already has User ForeignKey) #86

Closed
csarcom opened this issue Apr 2, 2014 · 6 comments
Closed
Labels
bug Issues related to confirmed bugs P3

Comments

@csarcom
Copy link

csarcom commented Apr 2, 2014

This is what I have:
https://gist.github.com/csarcom/9938033

Problem:

Exception: <class 'apps.user.models.CustomUserAccount'> has more than 1 ForeignKey to <class 'apps.user.models.CustomUser'>

My model should be ok with two foreign key to the same model using related_name right? But, since it is a through model, i guess django does not support it[1].

Any idea how can I save history_user on that model?

[1] https://code.djangoproject.com/ticket/8618

@treyhunner
Copy link
Member

I've never seen this before. According to that ticket it looks like you can't have two ForeignKey fields both using the same through model.

Maybe this is the main problem with #16 (many-to-many field support)?

@csarcom
Copy link
Author

csarcom commented Apr 2, 2014

The django ticket says that i can't have on through model two or more ForeignKey to source/target models. CustomUser and Account in my exemple.

Issue #16 objective is to allow keep history of m2m fields, right? Should it include in the history object through model fields too(field 'role' in my case)?

I want to keep history/history_user of fields that are in the through model(role and others...), I don't need to keep history of my m2m to Account(not for that m2m at least).

PS.: Maybe I'm not understand the big picture here :) let me know if is that the case.
PS2.: I have updated my gist.

@treyhunner
Copy link
Member

I have had not had any reason to look into many-to-many field tracking. Your issue is related to many-to-many field tracking, but your problem seems separate from the proposed solution in #16.

A ManyToManyField should probably be removed from the history model since it doesn't correspond to an actual database field. That would probably fix your specific problem, right?

@csarcom
Copy link
Author

csarcom commented Apr 7, 2014

Yes, my problem is separate from proposed solution in #16.

My point here is: We can't have in intermediate m2m model two ForeignKey to any of the models involved in the many-to-many.
changed_by field is a ForeignKey to User, if your intermediate model has a user model involved in the m2m, it wil thow an error.

Changed in Django Development version:
In Django 1.6 and earlier, intermediate models containing more than one foreign key to any of the models involved in the many-to-many relationship used to be prohibited.

Maybe in django 1.7 it will be fixed :)

@treyhunner treyhunner added the bug label Apr 7, 2014
@treyhunner
Copy link
Member

@csarcom you can try upgrading your current application to the Django 1.7 beta and see if it resolves the problem. I hope it does.

@treyhunner treyhunner added the P3 label Apr 7, 2014
@macro1
Copy link
Collaborator

macro1 commented Jan 4, 2016

Since 1.6.0 history_user no longer defaults to having a reverse relationship (#163), to avoid collisions like this.

Closing, should not be an issue anymore.

@macro1 macro1 closed this as completed Jan 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues related to confirmed bugs P3
Projects
None yet
Development

No branches or pull requests

3 participants