django-admin

Replacing django-admin's bootstrap theme's default logo

元气小坏坏 提交于 2021-01-05 11:20:28
问题 I have generated a django-admin for my app and I can access the dashboard. But it contains a logo that says "django admin". I want to change it to my own custom logo. How can I do that? I have tried adding a base.html file to admin directory and tried to override but for some reason it's not working. It's code is as follows: {% extends "admin/base.html" %} {% load theming_tags %} {% load staticfiles %} {% block blockbots %} {{ block.super }} {# Using blockbots ensures theming css comes after

Replacing django-admin's bootstrap theme's default logo

瘦欲@ 提交于 2021-01-05 11:16:07
问题 I have generated a django-admin for my app and I can access the dashboard. But it contains a logo that says "django admin". I want to change it to my own custom logo. How can I do that? I have tried adding a base.html file to admin directory and tried to override but for some reason it's not working. It's code is as follows: {% extends "admin/base.html" %} {% load theming_tags %} {% load staticfiles %} {% block blockbots %} {{ block.super }} {# Using blockbots ensures theming css comes after

How can I remove the add and change buttons from a TabularInline admin field?

China☆狼群 提交于 2021-01-02 07:48:54
问题 I have models A , B , and AB . A objects have a ManyToManyField called A.m that can link to many B objects, through my intermediary model AB . I have a very nice TabularInline section full of AB objects, on my admin page for my A model. All is well. Except that the TabularInline section shows "Add" and "Change" buttons for the B object in each AB object's row, and I want to remove those buttons. I still want to be able to add, change, and delete AB objects rows, just not the B objects they

How do I restrict access to admin pages in Django?

|▌冷眼眸甩不掉的悲伤 提交于 2020-12-28 07:55:41
问题 I need the Django admin interface to be accessible only for superusers and staff when in productions and show a 404 of all other types of users including when not logged in. Is this possible and how? 回答1: I ended up writing a middleware for it: from django.core.urlresolvers import reverse from django.http import Http404 class RestrictStaffToAdminMiddleware(object): """ A middleware that restricts staff members access to administration panels. """ def process_request(self, request): if request

How do I restrict access to admin pages in Django?

北城余情 提交于 2020-12-28 07:50:20
问题 I need the Django admin interface to be accessible only for superusers and staff when in productions and show a 404 of all other types of users including when not logged in. Is this possible and how? 回答1: I ended up writing a middleware for it: from django.core.urlresolvers import reverse from django.http import Http404 class RestrictStaffToAdminMiddleware(object): """ A middleware that restricts staff members access to administration panels. """ def process_request(self, request): if request

Troubleshooting “Related Field has invalid lookup: icontains”

主宰稳场 提交于 2020-12-27 08:20:08
问题 I have the following models in models.py : class ListinoTraduttore(models.Model): traduttore = models.ForeignKey('Traduttore', related_name='Traduttore') linguaDa = models.ForeignKey(Lingua, related_name = "linguaDa") linguaA = models.ForeignKey(Lingua, related_name = "linguaA") prezzoParola = models.CharField(max_length=50, blank=True) prezzoRiga = models.CharField(max_length=50, blank=True) scontoCat = models.CharField(max_length=50, blank=True) scontoFuzzy = models.CharField(max_length=50,

Is there a way to search for multiple terms in admin search? django

落爺英雄遲暮 提交于 2020-12-05 05:28:31
问题 In the django admin search bar if i had a model with a column = fruit_name and I wanted to search that column for all instances with either the fruit_name = banana or apple which would show all of the bananas and apples, how could I do that? 回答1: Override the ModelAdmin.get_search_results` method: from operator import or_ from django.db.models import Q class MyAdmin(admin.ModelAdmin): ... def get_search_results(self, request, queryset, search_term): queryset, use_distinct = super(MyAdmin,

Run django application without django.contrib.admin

拟墨画扇 提交于 2020-12-05 04:54:32
问题 I am trying to run my Django Application without Django admin panel because I don't need it right now but getting an exception value: Put 'django.contrib.admin' in your INSTALLED_APPS setting in order to use the admin application. Could I ran my application without django.contrib.admin ? Even if go my localhost:8000 it is showing you need to add django.contrib.admin in your installed_apps? 回答1: django.contrib.admin is simply a Django app. Remove or comment django.contrib.admin from INSTALLED

Django admin change_list view get ChangeList queryset - better solution than my monkey patch

元气小坏坏 提交于 2020-12-05 04:40:21
问题 I need to get a changelist view queryset in django admin. Currently, I have this monkey patch which makes 4 extra queries, so I'm looking for a better solution. My point is: I want to pass some extra values to django admin change_list.html template which I get from creating queries. For those queries, I need the queryset which is used in django admin changelist view with request filters applied. This is the same data which I see filtered, ordered etc. I want to make graphs from this data. Do

In Django admin, how to filter users by group?

筅森魡賤 提交于 2020-12-01 10:41:53
问题 It gives you filter by staff status and superuser status, but what about groups? 回答1: Since version 1.3 it can be done using this: list_filter = ('groups__name') Of course as @S.Lott explains you must register your customized class in the admin.py file: from django.contrib import admin from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User class MyUserAdmin(UserAdmin): list_filter = UserAdmin.list_filter + ('groups__name',) admin.site.unregister(User)