Merge pull request #157 from iamkhush/master

Admin Form Ordering using OrderDict  issue #153
This commit is contained in:
Camilo Nova 2016-09-10 18:24:17 -05:00 committed by GitHub
commit 07a00c44ee
2 changed files with 20 additions and 2 deletions

View file

@ -2,6 +2,7 @@ from datetime import datetime, date, time
from decimal import Decimal
import hashlib
from operator import itemgetter
from collections import OrderedDict
from django import forms, VERSION
from django.conf.urls import url
@ -202,7 +203,8 @@ class ConstanceAdmin(admin.ModelAdmin):
'config_values': config_values
})
context['config_values'].sort(key=itemgetter('name'))
if not isinstance(settings.CONFIG_FIELDSETS, OrderedDict):
context['config_values'].sort(key=itemgetter('name'))
request.current_app = self.admin_site.name
# compatibility to be removed when 1.7 is deprecated
extra = {'current_app': self.admin_site.name} if VERSION < (1, 8) else {}

View file

@ -118,8 +118,24 @@ Note: Use later evaluated strings instead of direct classes for the field and wi
'MY_SELECT_KEY': ('yes', 'select yes or no', 'yes_no_null_select'),
}
Ordered Fields in Django Admin
-----------------------
In order to Order the fields , you can use OrderedDict collection. Here is an example:
.. code-block:: python
from collections import OrderedDict
CONSTANCE_CONFIG = OrderedDict([
('SITE_NAME', ('My Title', 'Website title')),
('SITE_DESCRIPTION', ('', 'Website description')),
('THEME', ('light-blue', 'Website theme')),
]
Fieldsets
-------------
---------
To group settings together you can define fieldsets. Here's an example: