{"comment":{"url":"https://api.github.com/repos/ubc/edx-platform/comments/13428341","html_url":"https://github.com/ubc/edx-platform/commit/1aeb52f61824b35f42c0c25209e97bde767bb390#commitcomment-13428341","id":13428341,"user":{"login":"bradenmacdonald","id":945577,"avatar_url":"https://avatars.githubusercontent.com/u/945577?v=3","gravatar_id":"","url":"https://api.github.com/users/bradenmacdonald","html_url":"https://github.com/bradenmacdonald","followers_url":"https://api.github.com/users/bradenmacdonald/followers","following_url":"https://api.github.com/users/bradenmacdonald/following{/other_user}","gists_url":"https://api.github.com/users/bradenmacdonald/gists{/gist_id}","starred_url":"https://api.github.com/users/bradenmacdonald/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradenmacdonald/subscriptions","organizations_url":"https://api.github.com/users/bradenmacdonald/orgs","repos_url":"https://api.github.com/users/bradenmacdonald/repos","events_url":"https://api.github.com/users/bradenmacdonald/events{/privacy}","received_events_url":"https://api.github.com/users/bradenmacdonald/received_events","type":"User","site_admin":false},"position":41,"line":583,"path":"common/djangoapps/third_party_auth/models.py","commit_id":"1aeb52f61824b35f42c0c25209e97bde767bb390","created_at":"2015-09-25T00:24:47Z","updated_at":"2015-09-25T00:24:47Z","body":"This isn't working for me:\r\n![screen shot 2015-09-24 at 4 47 04 pm](https://cloud.githubusercontent.com/assets/945577/10090131/6e660dc6-62e0-11e5-8cc5-1b0e2e7c3164.png)\r\n\r\nA better approach in this case would be to define the choices on the admin form:\r\n\r\n```python\r\nclass ApiPermissionsAdminForm(forms.ModelForm):\r\n    class Meta:\r\n        model = ApiPermissions\r\n\r\n    provider_id = forms.ChoiceField(choices=[], required=True)\r\n\r\n    def __init__(self, *args, **kwargs):\r\n        super(ApiPermissionsAdminForm, self).__init__(*args, **kwargs)\r\n        self.fields['provider_id'].choices = ((provider.provider_id, provider.name) for provider in Registry.enabled())\r\n\r\n\r\nclass ApiPermissionsAdmin(admin.ModelAdmin):\r\n    \"\"\" Django Admin class for ApiPermissions \"\"\"\r\n    list_display = ('client', 'provider_id')\r\n    form = ApiPermissionsAdminForm\r\n\r\n\r\nadmin.site.register(ApiPermissions, ApiPermissionsAdmin)\r\n```\r\n\r\nThis is better because:\r\n* It works\r\n* You can use `from .provider import Registry` at the top of `admin.py` with no circular import issues\r\n* It doesn't use any of Django's private APIs\r\n* It displays the friendly name of each provider, which is preferable to the ID.\r\n* You can get rid of the new `get_provider_choices` and `get_all_provider_ids` methods."}}