how to force which base file is used in template - django

I would like to add custom view/template into the admin which I succeeded . But my issue here is that when I extends the base.html it takes the one from my project template and I would like to be able to tell django to take the one from mezzanine admin (as it is a admin page and i would like to have the same look and feel as the rest of the admin)
Any idea how to force the template resolution ?

There are no special template names in django; "base.html" is just the conventional name for the template at the top of the template inheritance tree (which is not required to have a single parent or any particular structure at all).
In terms of templating, django admin is just another django app. The first step is to figure out which template contains the style and content you want to inherit. For this task, I use django-debug-toolbar, which has a "Templates" panel which makes it very easy to figure out what content is coming from which template.
Looking at a django-debug-toolbar in the admin of a mezzanine site, you probably want to inherit from either "admin/base.html" or "admin/base_site.html" depending on how integrated your view is going to be with the admin site.

Related

How to override Django admin delete_selected_confirmation.html

In my Django admin. If I delete anything in superadmin or inside an user created by superadmin it shows a confirmation page. I have delete_confirmation.html in my templates under my admin and in my another app.
If I change anything in it or add a line it doesn't change plus it shows objects in my page which I don't want. I don't know how to override it. Please refer to the image. My delete confirmation page
To override any template in a django project, you need to replicate the path of the template in your project's template directory.
This template is found in contrib/admin/templates/admin/delete_confirmation.html
Therefore in your template directory create a directory called admin and then delete_confirmation.html in that. This overrides the django template path in your templates.
You can then put whatever you want in it & repeat this for any other templates from installed packages.
Docs on overrides of admin templates; https://docs.djangoproject.com/en/3.0/ref/contrib/admin/#admin-overriding-templates

Adding Wagtail to an existing Django app

I'm quite new to Django and Wagtail, and I'm having some difficulty with what I think is a very basic use.
How do I allow Wagtail to edit an existing view's template, while serving that template using Django's serving mechanism?
Assume I have an app (HomePage) created to serve the site's main index (/). I have the HomePage's views set up to render template and certain elements dynamically. Now I want that template to be editable via Wagtail's CMS interface. Something as simple as an image on the frontpage, or a headline.
The closest I've gotten so far has been to follow the Wagtail beginner's tutorial to override the base HomePage class in my app's models.py. That only made my pages available via the /pages/ URL.
Thank you for any help.
Since your site's home page is not a Page object in the Wagtail sense, I'd suggest looking at Wagtail's facilities for managing non-page content - snippets and ModelAdmin would be possible candidates, but I reckon the site settings module would be the best fit.
A Setting model gives you a set of fields which can be configured for display in the Wagtail admin using a 'panels' definition, just like you'd get for a page model - with the important property that only one settings record exists per site. You can retrieve this record within your homepage view or template as shown in the docs, and output it on your template as desired.
One way do that, is to let Wagtail serve your homepage. You will need to change your project's url configuration accordingly, to make wagtail's urls serve the root of your site.
Then, you can pack your dynamic content into a custom template_tag and include in your homepage html template.

How to make customized admin template work with grappelli?

I am sing grappelli, the admin pages look good, but now I need modify some pages, for example, I created templates/admin/index.html under my app, it works, but grappelli doesn't apply the style on this customized template, any idea how I can make it work as the default admin templates?
figured out, I need customize on the grappelli template files not the default admin template files

Django model layout with multiple columns

My admin page for a specific model has two stackedInlines. Currently they display one under the other. I would like them to display side by side so The page would look like this (don't have enough reputation to embed the image :[ )
Any easy way to go about this without having to write my own admin page?
If that's the only solution, how exactly would I go about that?
you can override Django admin template for each app in your project.
you just have too create same folder as your app in template directory and overriding html.
How to override and extend basic Django admin templates?
You can add CSS/Javascript to admin page by defining class Media.
You'll have to override the admin template to accomplish this. See roshan's answer for more info.

Modifying the django-cms 'add plugin' template on a per plugin basis?

The template I'm specifically talking about is the one that is used when a user add's a plugin to a page. Both in the admin area, and when modifying pages directly, it is displayed using an iframe.
The template itself is located cms/templates/admin/cms/page/plugin_change_form.html.
My problem is that I need some javascript to populate a drop down list within the form. All the javascript is run before the iframe is added to the page though, so I thought if I managed to edit the template I can tell the iframe to load some specific js. I can obviously just change the template directly, but that's a bit of an undesirable solution. I would rather keep it within the django application and even better have the js run only on specific plugins.
Any thoughts are appreciated.
You can set the change_form_template on your CMSPluginBase subclass, as CMSPluginBase is a subclass of django.contrib.admin.options.ModelAdmin.