django-admin

django admin override filter_horizontal

☆樱花仙子☆ 提交于 2021-02-07 03:49:25
问题 I'm aiming to make an "advanced" filter_horizontal, one with more filters, but I can't seem to find the widget to override. I know it uses the related_widget_wrapper.html, but if I want to add functionalities to it in a clear way, what is the widget to override. For now my backup solution is to do a full javascript solution to prepend it with a dropdown on form load (created from javascript) and make ajax calls to modify the filter...but this seems as an overkill. What i've done so far : #

Admin FileField current url incorrect

血红的双手。 提交于 2021-02-06 11:22:45
问题 In the Django admin, wherever I have a FileField, there is a "currently" box on the edit page, with a hyperlink to the current file. However, this link is appended to the current page url, and therefore results in a 404 as there is no such page as, for example: http://127.0.0.1:8000/admin/Tank/asset/17/media/datasheet/13/09/05/copyright.html/ For reference, the correct url of the file is: http://127.0.0.1:8000/media/datasheet/13/09/05/copyright.html Is there any way to fix this problem in the

How to use Django QuerySet.union() in ModelAdmin.formfield_for_manytomany()?

て烟熏妆下的殇ゞ 提交于 2021-02-05 06:10:26
问题 Not sure what I am doing wrong here: I tried to use QuerySet.union(), in Django 2.2.10, to combine two querysets (for the same model) inside ModelAdmin.formfield_for_manytomany() . However, when the form is saved, the entire queryset is selected, regardless of the actual selection made. Please consider the minimal example below, based on the standard Django Article/Publication example. from django.db import models from django.contrib import admin class Publication(models.Model): pass class

How to use Django QuerySet.union() in ModelAdmin.formfield_for_manytomany()?

两盒软妹~` 提交于 2021-02-05 06:10:14
问题 Not sure what I am doing wrong here: I tried to use QuerySet.union(), in Django 2.2.10, to combine two querysets (for the same model) inside ModelAdmin.formfield_for_manytomany() . However, when the form is saved, the entire queryset is selected, regardless of the actual selection made. Please consider the minimal example below, based on the standard Django Article/Publication example. from django.db import models from django.contrib import admin class Publication(models.Model): pass class

Django admin: adding pagination links in list of objects to top

元气小坏坏 提交于 2021-02-05 05:23:12
问题 Is it possible to have the pagination links that appear at the bottom of a list of objects in Django's admin interface at the top as well? Can this be done without changing the admin templates? I suspect not, given the lack of a ModelAdmin option, but thought I'd see if anyone had done this before I dug into the template code. I really, really don't want to have to copy and paste change_list.html into a new file, just so I can add a pagination line - that'll make changing Django versions

Add custom button to django admin panel

时光总嘲笑我的痴心妄想 提交于 2021-02-04 12:36:05
问题 I want to add button to admin panel to my model, I have overwrite template (path: templetes/admin/myapp/mymodel/change_list.html ) change_list.html {% extends "admin/change_list.html" %} {% load i18n admin_static %} {% block result_list %} <div class="object-tools"> <a href="{% url 'myurl' %}" class="btn btn-high btn-success">Import</a> </div> {{ block.super }} {% endblock %} In admin.py class ImportAdmin(admin.ModelAdmin): change_list_template = 'admin/myapp/mymodel/change_list.html' But I

Django admin tabular inline lookup select dropdown box for a very large queryset

时光毁灭记忆、已成空白 提交于 2021-01-29 15:25:43
问题 I have a django admin tabular inline, in which I have form = ProdForm which holds a modelchoicefield select box as follows; class ProdForm(forms.ModelForm): productid = forms.ModelChoiceField(queryset=Product.objects.filter(active=True), widget=Select2(select2attrs={"width": "400px"}), ) as you can see, I am using the easy_select2 module, that is enabling providing me with a look up field too. However, if I try to load this in the corresponding tabularInLine, it never loads because there is a

Recursive relationship in Django: get all the interrelated records from each record

戏子无情 提交于 2021-01-29 15:13:44
问题 I have this model for a tune: class MsTune(models.Model): name = models.CharField(max_length=255) ms = models.ForeignKey(Manuscript, on_delete=models.CASCADE, related_name="mstunes") concordances = models.ManyToManyField("self", blank=True) I have many manuscripts (ms), and the same tune might appear in more than one manuscript. What I want to do, with that concordances field, is link all the similar tunes. This works, in part. The Django administration back-end allows me to select many tunes

After an upgrade from Django 1.11 to Django 3.1 django admin shows list of models on top of internal items

余生长醉 提交于 2021-01-29 14:24:16
问题 After an upgrade from Django 1.11 (python2.7) to Django 3.1 (python3.6) on Centos7, django admin still shows the list of models on top of the page, above the list of items in this model. Before the upgrade, the admin showed everything correctly: you see a list, you enter an item and see a screen related to this item, no more lists. Please see the related screenshots: Please advise how to solve this. 回答1: maybe you need to re-run collectstatic command python manage.py collectstatic refer to

Django Admin Issue - 'NoneType' object has no attribute 'user'

天涯浪子 提交于 2021-01-29 08:25:13
问题 Writing a blog engine with Django 1.5 and using the Django Admin. Everything was fine, until I added a ManyToManyField to a model, and added that field to the ModelAdmin's fieldsets, then I started to get this mysterious error when trying to load the admin page: 'NoneType' object has no attribute 'user' (Full stack trace further on below.) Why would the response object suddenly be None? If I remove the field from the fieldset, everything's fine again. My models look something a bit like this