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

It is almost possible to embed the dashboard views in a Django admin template #114

Open
toolness opened this issue May 20, 2021 · 2 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@toolness
Copy link
Contributor

Hello again! I've got the dashboard up and running on my site and it's working great.

One thing I'd like to do, if possible, is style the dashboard views so that they look like they're part of the admin site (since on my site, they are accessible only to staff, from the Django admin). On a lark, I tried setting my django_sql_dashboard/base.html to the following:

{% extends "admin/base_site.html" %}
{% load static %}

{% block extrahead %}
<style>{% include "django_sql_dashboard/_css.html" %}</style>
{% endblock %}

This actually came really close to working! I'm not sure if it was intentional on your part, but django-sql-dashboard's custom CSS melds with the admin site's CSS quite nicely:

image

There are two problems, though:

  1. The template isn't being passed the context of AdminSite.each_context(), so a bunch of stuff that's usually shown in the header isn't being shown. If there were a way to pass custom context to the dashboard views, it would be awesome.

  2. The title displays twice, I feel like there should be an easy way around this, but the only thing I can think of right now is a horrible CSS hack:

    h1 ~ h1 {
      display: none;
    }

Anyways, I guess that means (1) is the only real blocker for me. Looking at django-sql-dashboard's code, I can't see any easy way of injecting extra context into the dashboard views. One possibility I can think of might be to add optional extra_context arguments to the views, which I'd be happy to submit a PR for. Anyways, let me know if you have any thoughts!

@simonw simonw added documentation Improvements or additions to documentation enhancement New feature or request labels May 25, 2021
@simonw
Copy link
Owner

simonw commented May 25, 2021

Having this as a documented, supported way of using the tool makes a ton of sense to me. I like the pattern of wrapping the Django SQL Dashboard view with a custom view to add extra context - an extra_context= argument sounds like it could help there.

I don't understand why the title shows twice, but we should definitely find a fix for that!

PRs welcome for this.

@toolness
Copy link
Contributor Author

toolness commented Aug 6, 2021

Hey, I just noticed that you mentioned this over in #127 (comment):

I think the way to address this would be to switch over to more of a class-based-view approach to allow people to subclass the dashboard views and implement things like their own custom permissions.

While this issue isn't directly related to that one, I think that a good solution to this one might be the same kind of thing--moving the views over to more of a class-based-view approach that would allow these sorts of things to be easily customized. Anyways, just a random thought I figured I'd log here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants