{"action":"created","issue":{"url":"https://api.github.com/repos/stephenmcd/mezzanine/issues/1568","repository_url":"https://api.github.com/repos/stephenmcd/mezzanine","labels_url":"https://api.github.com/repos/stephenmcd/mezzanine/issues/1568/labels{/name}","comments_url":"https://api.github.com/repos/stephenmcd/mezzanine/issues/1568/comments","events_url":"https://api.github.com/repos/stephenmcd/mezzanine/issues/1568/events","html_url":"https://github.com/stephenmcd/mezzanine/issues/1568","id":141894845,"number":1568,"title":"UserProfile cannot have Multiple Foreign keys to User","user":{"login":"mmansour","id":857870,"avatar_url":"https://avatars.githubusercontent.com/u/857870?v=3","gravatar_id":"","url":"https://api.github.com/users/mmansour","html_url":"https://github.com/mmansour","followers_url":"https://api.github.com/users/mmansour/followers","following_url":"https://api.github.com/users/mmansour/following{/other_user}","gists_url":"https://api.github.com/users/mmansour/gists{/gist_id}","starred_url":"https://api.github.com/users/mmansour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmansour/subscriptions","organizations_url":"https://api.github.com/users/mmansour/orgs","repos_url":"https://api.github.com/users/mmansour/repos","events_url":"https://api.github.com/users/mmansour/events{/privacy}","received_events_url":"https://api.github.com/users/mmansour/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-18T15:15:03Z","updated_at":"2016-03-19T15:49:10Z","closed_at":null,"body":"To replicate: \r\n\r\nCreate UserProfile as per mezz docs\r\n\r\n```\r\nclass UserProfile(models.Model):\r\n    user = models.OneToOneField('auth.User', blank=True, null=True, related_name='userprofile')\r\n    owner = models.ForeignKey('auth.User', blank=True, null=True, related_name='subordinates')\r\n```\r\n\r\nRun 'makemigrations'. You'll get the following error: \r\n\r\n> '*appname*.UserProfile' has more than one ForeignKey to 'auth.User'.\r\n\r\n\r\nThe issue seems to be stemming from the mezzanine.accounts.admin profile inlines: \r\n\r\nIf I add : \r\n\r\n`fk_name = 'user'`\r\n\r\nto the body of the ProfileLineClass the issue is fixed. \r\n\r\n```\r\ntry:\r\n    class ProfileInline(admin.StackedInline):\r\n        model = get_profile_model()\r\n        can_delete = False\r\n        fk_name = 'user'   # ADDED HERE\r\n        template = \"admin/profile_inline.html\"\r\n        extra = 0\r\n    UserProfileAdmin.inlines += (ProfileInline,)\r\nexcept ProfileNotConfigured:\r\n    pass\r\n```\r\n\r\nIf this is a bug (and an acceptable fix) I am happy to fix and submit a pr. However, this would require a convention that everyone name their OneToOneField 'user' in their User Profile model. \r\n\r\nThe need to have multiple foreign keys to the user model from userprofile does not seem like that much of an edge case. The above approach seems like a reasonable one to create users that can be owners/admins of other users, yet not staff. However, if this is not a bug and there is a better approach then the one I am taking to achieve this I am open to it. Please let me know!\r\n\r\nCheers\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/stephenmcd/mezzanine/issues/comments/198736397","html_url":"https://github.com/stephenmcd/mezzanine/issues/1568#issuecomment-198736397","issue_url":"https://api.github.com/repos/stephenmcd/mezzanine/issues/1568","id":198736397,"user":{"login":"jerivas","id":2391102,"avatar_url":"https://avatars.githubusercontent.com/u/2391102?v=3","gravatar_id":"","url":"https://api.github.com/users/jerivas","html_url":"https://github.com/jerivas","followers_url":"https://api.github.com/users/jerivas/followers","following_url":"https://api.github.com/users/jerivas/following{/other_user}","gists_url":"https://api.github.com/users/jerivas/gists{/gist_id}","starred_url":"https://api.github.com/users/jerivas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jerivas/subscriptions","organizations_url":"https://api.github.com/users/jerivas/orgs","repos_url":"https://api.github.com/users/jerivas/repos","events_url":"https://api.github.com/users/jerivas/events{/privacy}","received_events_url":"https://api.github.com/users/jerivas/received_events","type":"User","site_admin":false},"created_at":"2016-03-19T15:49:10Z","updated_at":"2016-03-19T15:49:10Z","body":"So after reading the comments on the mailing list I think the underlying issue here is that Mezzanine will automatically create an InlineAdmin for the profile model, and the developer has no control over it. Instead of providing hooks for some or all options, we should simply create a new setting to store the dotted path to an InlineAdmin class where one can do whatever is best for the case.\r\n\r\n`AUTH_PROFILE_INLINE_ADMIN = \"myapp.admin.ProfileInlineAdmin\"`\r\n\r\nThe current implementation could be used as the default value for the setting, so it should be 100% backwards compatible (it could live in `mezzanine.accounts.admin`). Custom admin classes could also inherit from it to easily override it."}}