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

[admin] Make organization selection automatic when only 1 org #170

Closed
nemesifier opened this issue Aug 23, 2020 · 6 comments
Closed

[admin] Make organization selection automatic when only 1 org #170

nemesifier opened this issue Aug 23, 2020 · 6 comments
Assignees

Comments

@nemesifier
Copy link
Member

When the user logged in has access to only one organization, the organization select should automatically set that org as the default value, the user should not need to select it.

@nemesifier
Copy link
Member Author

Update:

this could do the trick: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_for_choice_field

if len(request.user.organizations_managed) <= 1:
    kwargs['initial'] = request.user.organizations_maanged[0]

I have not tested this.

@pniaps
Copy link
Member

pniaps commented Aug 25, 2020

I think that way would require code in all ModelAdmin where the model uses organization field.

I'm testing with the field, something like adding a default value to the field https://github.com/openwisp/openwisp-users/blob/master/openwisp_users/mixins.py#L84

Let me think about your suggestion, I didn't knew about organizations_managed but its a good point.

@nemesifier
Copy link
Member Author

I think that way would require code in all ModelAdmin where the model uses organization field.

Not exactly. All the modules which support multitenancy inherit this mixin:
https://github.com/openwisp/openwisp-users/blob/master/openwisp_users/multitenancy.py#L11

So it should be enough to implement it once for every multi-tenant admin.

@pniaps
Copy link
Member

pniaps commented Aug 25, 2020

Great, I will try it.
Thanks.

@atb00ker atb00ker added the Hacktoberfest Easy issues for attracting Hacktoberfest participants. label Sep 23, 2020
niteshsinha17 added a commit to niteshsinha17/openwisp-users that referenced this issue Nov 12, 2020
niteshsinha17 added a commit to niteshsinha17/openwisp-users that referenced this issue Nov 22, 2020
niteshsinha17 added a commit to niteshsinha17/openwisp-users that referenced this issue Nov 28, 2020
niteshsinha17 added a commit to niteshsinha17/openwisp-users that referenced this issue Jan 7, 2021
niteshsinha17 added a commit to niteshsinha17/openwisp-users that referenced this issue Feb 22, 2021
niteshsinha17 added a commit to niteshsinha17/openwisp-users that referenced this issue Apr 1, 2021
@keshavgbpecdelhi
Copy link

Well done.

@nemesifier nemesifier removed the Hacktoberfest Easy issues for attracting Hacktoberfest participants. label Oct 1, 2021
@nemesifier
Copy link
Member Author

Implemented in #333.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants