[admin] Make organization selection automatic when only 1 org
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.
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.
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.
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.
Great, I will try it. Thanks.
Well done.
Implemented in https://github.com/openwisp/openwisp-users/issues/333.