django-admin

Edit Django admin logout template?

↘锁芯ラ 提交于 2021-02-20 10:31:53
问题 I want to make a very small change to the Django admin logout page. I know how to use templates to override the Django admin templates, so I have tried to do the same thing with the logout file. I have set up a new template at templates/registration/logged_out.html . The content of this file is as follows: {% extends "registration/logged_out.html" %} {% block content %} <p>Thanks for using the site.</p> <p><a href="../">Log in again</a></p> <p><a href="/">Return to the home page</a></p> {%

Edit Django admin logout template?

岁酱吖の 提交于 2021-02-20 10:31:05
问题 I want to make a very small change to the Django admin logout page. I know how to use templates to override the Django admin templates, so I have tried to do the same thing with the logout file. I have set up a new template at templates/registration/logged_out.html . The content of this file is as follows: {% extends "registration/logged_out.html" %} {% block content %} <p>Thanks for using the site.</p> <p><a href="../">Log in again</a></p> <p><a href="/">Return to the home page</a></p> {%

Displaying foreign model fields in django admin as editable

给你一囗甜甜゛ 提交于 2021-02-19 11:28:26
问题 I have a Django Model with a Foreign key: class Library: name=models.CharField() class Book: title=models.CharField() library=models.ForeignKey(Library) models.py class BookAdmin(admin.ModelAdmin): extra = 0 fields = ['title', 'library__name'] # library__name not found admin.site.register(Book, BookAdmin) admin.py In the admin, I want to display Book and show an editable field for Library.name in the Book view (not the other way around with inlines): > Book * Title: "Foo" * Library Name: "Bar

how to display inline elements in list_display?

我怕爱的太早我们不能终老 提交于 2021-02-19 04:13:30
问题 I have the following problem: I have two models: Article and Comment, in Comments, i have parent = models.ForeignKey(Article). I have it set up so that Comments is inline to ArticleAdmin(admin.ModelAdmin), and CommentInline(admin.StackedInline). What i would like is that for Article list view (elements chosen in list_display), I would like to display snippets of latest comments so that the user does not have to click into each individual comments to see the changes. Now i know that i can

django admin - You don't have permission to edit anything

大城市里の小女人 提交于 2021-02-19 00:53:21
问题 I followed the django doc on creating a custom user model while extending the model itself with my own fields. So it became like this: class MyUser(AbstractBaseUser, PermissionsMixin): email = models.EmailField(max_length=255, unique=True) first_name = models.CharField(max_length=35) last_name = models.CharField(max_length=35) username = models.CharField(max_length=70, unique=True) date_of_birth = models.DateField() is_active = models.BooleanField(default=True) is_admin = models.BooleanField

django admin - You don't have permission to edit anything

拥有回忆 提交于 2021-02-19 00:46:18
问题 I followed the django doc on creating a custom user model while extending the model itself with my own fields. So it became like this: class MyUser(AbstractBaseUser, PermissionsMixin): email = models.EmailField(max_length=255, unique=True) first_name = models.CharField(max_length=35) last_name = models.CharField(max_length=35) username = models.CharField(max_length=70, unique=True) date_of_birth = models.DateField() is_active = models.BooleanField(default=True) is_admin = models.BooleanField

Django signals from admin

此生再无相见时 提交于 2021-02-16 09:24:10
问题 How can I distinguish between, for example, a post_save that comes from a regular view and one that comes from the admin? 回答1: By overriding ModelAdmin.response_add you may get a similar functionality, as it seems that the django admin does not sent any signals. The response_add function gets called after it successfully validated and added all data, such as related fields but also the object itself. So by overriding the response_add method in our own ModelAdmin class we can execute code

Django 3.1 | Admin page appearance issue

♀尐吖头ヾ 提交于 2021-02-15 11:23:18
问题 Today I have updated Django to latest version 3.1. But for some reason when the logged in to admin page, all I cans see is a weird looking admin page. admin.py Can someone help me what went wrong or what are things I need to modify to get back to original admin page. Thanks in advance 回答1: In your projects' root urls.py file, simply add the below code to disable the new sidebar feature. from django.contrib import admin admin.autodiscover() admin.site.enable_nav_sidebar = False Reference:

Django 3.1 | Admin page appearance issue

匆匆过客 提交于 2021-02-15 11:23:10
问题 Today I have updated Django to latest version 3.1. But for some reason when the logged in to admin page, all I cans see is a weird looking admin page. admin.py Can someone help me what went wrong or what are things I need to modify to get back to original admin page. Thanks in advance 回答1: In your projects' root urls.py file, simply add the below code to disable the new sidebar feature. from django.contrib import admin admin.autodiscover() admin.site.enable_nav_sidebar = False Reference:

Check admin login on my django app

偶尔善良 提交于 2021-02-11 18:06:49
问题 I have created a django app and have linked to the admin index page by modifying base.html. However, the link of the app is accessible directly as well. Can I check on the page or in the views.py of my app if the user is logged in to the django admin or not? 回答1: Use the @staff_member_required decorator: from django.contrib.admin.views.decorators import staff_member_required @staff_member_required def my_view(request): ... 回答2: from django.contrib.auth.decorators import user_passes_test @user