django-admin

Check admin login on my django app

时光毁灭记忆、已成空白 提交于 2021-02-11 18:04:09
问题 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

Use Django password widget and change password form in user admin site

落爺英雄遲暮 提交于 2021-02-11 17:09:53
问题 I am extending the user model in Django and have create a PIN number field that is hashing into the database correctly. However, in the Django admin when viewing a user the pin number field is populated with the hash. Is it possible to use the Django password widget: so that the PIN number field is not populated: and therefore by extension use the template for the change password form to also change the pin? 回答1: I don't see why you couldn't use the form. Here's the Django User form: django

Use Django password widget and change password form in user admin site

☆樱花仙子☆ 提交于 2021-02-11 17:08:33
问题 I am extending the user model in Django and have create a PIN number field that is hashing into the database correctly. However, in the Django admin when viewing a user the pin number field is populated with the hash. Is it possible to use the Django password widget: so that the PIN number field is not populated: and therefore by extension use the template for the change password form to also change the pin? 回答1: I don't see why you couldn't use the form. Here's the Django User form: django

Django Admin - display image on hover

☆樱花仙子☆ 提交于 2021-02-11 14:21:43
问题 I'd like to display a thumbnail in a popover when I hover over text (a camera emoji) in our Django Admin view. The code I have works, but displays the image inline, which disrupts the rest of the layout of the site I'm by no means a Django expert, so there might be something easy I'm missing. I'm totally open to using other libraries to help if that's the best path forward, but am not sure of how to appropriately load them in to django admin. I'm also open to pure js/css solutions - whatever

Override Navbar in Django base admin page to be same as the base.html

情到浓时终转凉″ 提交于 2021-02-11 13:32:06
问题 In my django admin pages, I would like to override the navbar (top ribbon) to be the same as the one in my "base.html" template. For different reasons: Users can navigate through the website even when they are in the admin views. To keep same style across pages, even in admin pages. I am using django 2.2.6. I don't really know how to start and what would be the best approach. Any advices of how you would do this ? EDIT1: I was thinking about creating a base_site.html file within "templates

How do I trigger a Celery task from Django admin?

北城以北 提交于 2021-02-11 07:56:11
问题 I have a model called Publication and I'd like to add a button to the list view in Django Admin which would allow triggering a Celery task. admin.py : from django.contrib import admin from .models import Publication class PublicationAdmin(admin.ModelAdmin): change_list_template = "variants/admin_publication_list.html" def update(self, request): # trigger task # redirect to admin list admin.site.register(Publication, PublicationAdmin) variants/admin_publication_list.html : {% extends 'admin

ValidationError [u'ManagementForm data is missing or has been tampered with'] only in special cases

好久不见. 提交于 2021-02-10 14:56:23
问题 When editing a model field through Django Admin, I'm getting a [u'ManagementForm data is missing or has been tampered with'] validation error. Steps: Edit a model through Django Admin and insert a special character (é,ñ) The data is saved OK. When editing again the model field (charField) the validation error is raised, whatever the input is. When editing without special characters, the form is working ok. Edit When saving a special character, the inlines for that model doesn't show up in the

many-to-many relationship of wagtail page model to itself?

巧了我就是萌 提交于 2021-02-10 14:47:44
问题 So i got a PlantDetailPage model with "companion" field among others (yes plants can be companions), in which I should be able to select other PlantDetailPages. I got the thing to show up, create new plants in inline (yes, a menu in the menu in the menu...), but there's few issues: 1) It just won't select them (no action on clicking "select plantdetailpage") 2) "companions" menu button is now shown on the left (like a snippet that it became?) - which I'd like to avoid. 3) I don't know how to

Django Get ID of the object in save()

雨燕双飞 提交于 2021-02-10 07:10:36
问题 I have some fixed number let say it is num = 1000 Now I have field which need to be sum of the object.id and num. I need this in save() something like below. def save(self, *args, **kwargs): num = 1000 self.special = self.id + num super(MyModel, self).save(*args, **kwargs) But self.id is known after save and field named special is required. How to get self.id? 回答1: First of all? Is the number you're trying to add a fixed number? If so, why do you have to store it in the db at all? You may

Django Get ID of the object in save()

北城余情 提交于 2021-02-10 07:08:02
问题 I have some fixed number let say it is num = 1000 Now I have field which need to be sum of the object.id and num. I need this in save() something like below. def save(self, *args, **kwargs): num = 1000 self.special = self.id + num super(MyModel, self).save(*args, **kwargs) But self.id is known after save and field named special is required. How to get self.id? 回答1: First of all? Is the number you're trying to add a fixed number? If so, why do you have to store it in the db at all? You may