django-admin

How to filter ModelAdmin autocomplete_fields results with the context of limit_choices_to

痴心易碎 提交于 2020-05-15 08:01:06
问题 I have a situation where I wish to utilize Django's autocomplete admin widget, that respects a referencing models field limitation. For example I have the following Collection model that has the attribute kind with specified choices. class Collection(models.Model): ... COLLECTION_KINDS = ( ('personal', 'Personal'), ('collaborative', 'Collaborative'), ) name = models.CharField() kind = models.CharField(choices=COLLECTION_KINDS) ... Another model ScheduledCollection references Collection with a

Django conditional admin list_editable

谁都会走 提交于 2020-05-12 11:46:09
问题 Is there anyway to make the list_editable optional on a per object bases? For example the readonly fields attribute has this option, which doesn't affect the changelist_view. class MyAdmin(admin.ModelAdmin): readonly_fields = ('foo',) def get_readonly_fields(self, request, obj=None): fields = super(MyAdmin, self).get_readonly_fields(request, obj=obj) if obj.status == 'CLOSED': return fields + ('bar',) return fields The same can be achieved for list_display and some other attributes. It seems

Localization: django-admin compilemessages skip venv

孤者浪人 提交于 2020-05-11 04:55:31
问题 I am using localization in Django 1.11 application. I can exclude the virtual environment folder and node_modules folder while adding the messages in message file using -i option like: django-admin makemessages -l 'no' -i venv django-admin makemessages -d djangojs --locale no -i venv -i node_modules After adding the translations I am compiling messages using: django-admin compilemessages It processes django.po files of all installed packages located in virtual environment folder. Thus it

Localization: django-admin compilemessages skip venv

孤街醉人 提交于 2020-05-11 04:54:07
问题 I am using localization in Django 1.11 application. I can exclude the virtual environment folder and node_modules folder while adding the messages in message file using -i option like: django-admin makemessages -l 'no' -i venv django-admin makemessages -d djangojs --locale no -i venv -i node_modules After adding the translations I am compiling messages using: django-admin compilemessages It processes django.po files of all installed packages located in virtual environment folder. Thus it

Django admin terrible performance get_form queryset filter when adding order_by

时间秒杀一切 提交于 2020-04-30 16:35:38
问题 I'm encountering some terrible performance issues when trying to filter a forms queryset. I'm trying to filter a Model where a relationship already exists. The code is successful. But my queryset is not ordered. The moment I change to form.base_fields['sharepoint_mandate'].queryset = Sharepoint_Mandate.objects.filter(mandate_mapping_2__isnull=True).order_by('product_name') the query now takes 25 seconds Please help models.py class Mandate_Mapping_2(Trackable): mandate_mapping_id = models

Django Admin Create Form Inline OneToOne

好久不见. 提交于 2020-04-30 09:07:29
问题 I have the following model: from django.db import models class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) last_password_reset = models.DateTimeField(auto_now_add=True) needs_password_reset = models.BooleanField(default=True) image_url = models.URLField(max_length=500, default=None, null=True, blank=True) I am trying to inline this into the admin. I have the following: from django import forms from django.contrib.auth.models import User from django

How to override the str method when rendering StackedInline field?

北城余情 提交于 2020-04-30 07:51:28
问题 I have a many to many relationship: class GroupeCategoriesCategorie(models.Model): groupe_categories = models.ForeignKey(GroupeCategories, related_name='groupe', verbose_name=_(u'Groupe')) categorie = models.ForeignKey(Categorie, related_name='categorie', verbose_name=_(u'Catégorie')) def __str__(self): return _(u'{} / {}').format(self.groupe_categories, self.categorie) I always need a representation like the __str__ method before except when rendering in the admin. Why? My admin.py looks

How to override the str method when rendering StackedInline field?

断了今生、忘了曾经 提交于 2020-04-30 07:51:01
问题 I have a many to many relationship: class GroupeCategoriesCategorie(models.Model): groupe_categories = models.ForeignKey(GroupeCategories, related_name='groupe', verbose_name=_(u'Groupe')) categorie = models.ForeignKey(Categorie, related_name='categorie', verbose_name=_(u'Catégorie')) def __str__(self): return _(u'{} / {}').format(self.groupe_categories, self.categorie) I always need a representation like the __str__ method before except when rendering in the admin. Why? My admin.py looks

how to limit django admin inline formsets

和自甴很熟 提交于 2020-04-29 10:19:18
问题 How do you limit the inline formset in django admin? Problem: I have a table A with 1 to n relationship with B. Table A should have at least one Table B item and a max of 5 Table B items. 回答1: http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-options Specify max_num in your Inline definition to limit the number. extra specifies how many blank inlines to show. Is the 1 inline required? As in you want to trigger a validation error if table B isn't filled with at least 1

Django Admin - login

大兔子大兔子 提交于 2020-04-16 04:36:16
问题 I'm building a Django Web App with Django Suit for the administration interface . Already got have Python 2.7, Django 1.10, and MySQL communicating in harmony and started a project: python -m django-admin startproject webapp So, those were the steps made in the Windows PowerShell after that: 1. Start our virtual env and run the server: PS C:\WINDOWS\system32> cd C:\PythonProjects PS C:\PythonProjects> virtualenvs\rrh\Scripts\activate (rrh) PS C:\PythonProjects> cd rrh/webapp 2. Setup Django