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

Dynamically set admin url name to be redirected to on action execution #49

Closed
An4ik opened this issue Oct 15, 2021 · 1 comment · May be fixed by #55
Closed

Dynamically set admin url name to be redirected to on action execution #49

An4ik opened this issue Oct 15, 2021 · 1 comment · May be fixed by #55

Comments

@An4ik
Copy link

An4ik commented Oct 15, 2021

I have a few admin pages i.g.

/admin/ ---> for company users (our company)
/c-admin --> for customer users
/super-admin/ ---> for me (everything is allowwed)

so I would like to add inline actions to /c-admin/ but after pressing it it will redirect to admin defaul one cause:
https://github.com/escaped/django-inline-actions/blob/master/inline_actions/admin.py#L205

if parent_obj is None:  # InlineActionsMixin.MODEL_ADMIN:
    # redirect to `changelist`
    url = reverse(
        'admin:{}_{}_changelist'.format(
            obj._meta.app_label,
            obj._meta.model_name,
        ),
    )
else:
    # redirect to `changeform`
    url = reverse(
        'admin:{}_{}_change'.format(
            parent_obj._meta.app_label,
            parent_obj._meta.model_name,
        ),
        args=(parent_obj.pk,),
    )

I the way I would like to handle it:

Read the admin url name from admin class. if it's not found use default admin but it can be also overridden in settings

For example:

def get_admin_url_base_name() --> str:
   """
   Return admin sitem base name can be extracted from self.admin_site
   """
   
 

  url = reverse(
        'admin:{}_{}_change'.format(
            parent_obj._meta.app_label,
            parent_obj._meta.model_name,
        ),
        args=(parent_obj.pk,),
    )

If you ok and agree with this issue I can handle it

bdnettleton added a commit to bdnettleton/django-inline-actions that referenced this issue Sep 15, 2022
Simple changes in admin.py to change reverse url lookup to use the proper admin site name instead of always using the default "admin".

Includes new custom_admin page in test_proj and tests to check that the reverse works properly.
@bdnettleton
Copy link

I hit this issue as well and have submitted a pull request with a fix to handle custom admin pages. No need to implement another function as you can simply get the custom admin site name from self.admin_site.name.

@An4ik An4ik closed this as completed Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants