Refactored admin url patterns to be compatible with Django 1.8 or higher.

Refactored sample_project imports to be compatible with Django 1.9
Updated unit tests for get_next/previous.
Version bump to 2.0.8.
Fixed typo in docs.
master
Brandon Taylor 2015-12-21 14:11:13 -05:00
parent ba9e477f2f
commit 698ca136d5
5 changed files with 41 additions and 20 deletions

View File

@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/iambrandontaylor/django-admin-sortable.svg?branch=master)](https://travis-ci.org/iambrandontaylor/django-admin-sortable) [![Build Status](https://travis-ci.org/iambrandontaylor/django-admin-sortable.svg?branch=master)](https://travis-ci.org/iambrandontaylor/django-admin-sortable)
Current version: 2.0.7 Current version: 2.0.8
This project makes it easy to add drag-and-drop ordering to any model in This project makes it easy to add drag-and-drop ordering to any model in
Django admin. Inlines for a sortable model may also be made sortable, Django admin. Inlines for a sortable model may also be made sortable,
@ -457,8 +457,11 @@ ordering on top of that just seemed a little much in my opinion.
django-admin-sortable is currently used in production. django-admin-sortable is currently used in production.
### What's new in 2.0.7? ### What's new in 2.0.8?
- Minor enhancement to determine which element to highlight on sortable stacked inlines when all fieldsets are set to collapse. - Refactored admin url patterns to be compatible with Django 1.8 or higher.
- Refactored import paths on generics in `sample_project` to be compatible with Django 1.9.
- Fixed typo in documentation.
- Updated unit tests for get_next/previous.
### Future ### Future

View File

@ -1,4 +1,4 @@
VERSION = (2, 0, 7) # following PEP 386 VERSION = (2, 0, 8) # following PEP 386
DEV_N = None DEV_N = None

View File

@ -4,10 +4,12 @@ from django import VERSION
from django.conf import settings from django.conf import settings
if VERSION < (1, 5): if VERSION > (1, 7):
from django.conf.urls.defaults import patterns, url from django.conf.urls import url
else: elif VERSION > (1, 5):
from django.conf.urls import patterns, url from django.conf.urls import patterns, url
else:
from django.conf.urls.defaults import patterns, url
from django.contrib.admin import ModelAdmin, TabularInline, StackedInline from django.contrib.admin import ModelAdmin, TabularInline, StackedInline
from django.contrib.admin.options import InlineModelAdmin from django.contrib.admin.options import InlineModelAdmin
@ -80,17 +82,27 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
def get_urls(self): def get_urls(self):
urls = super(SortableAdmin, self).get_urls() urls = super(SortableAdmin, self).get_urls()
admin_urls = patterns('',
# this ajax view changes the order # this ajax view changes the order
url(r'^sorting/do-sorting/(?P<model_type_id>\d+)/$', admin_do_sorting_url = url(r'^sorting/do-sorting/(?P<model_type_id>\d+)/$',
self.admin_site.admin_view(self.do_sorting_view), self.admin_site.admin_view(self.do_sorting_view),
name='admin_do_sorting'), name='admin_do_sorting')
# this view displays the sortable objects # this view displays the sortable objects
url(r'^sort/$', self.admin_site.admin_view(self.sort_view), admin_sort_url = url(r'^sort/$',
name='admin_sort'), self.admin_site.admin_view(self.sort_view),
) name='admin_sort')
if VERSION > (1, 7):
admin_urls = [
admin_do_sorting_url,
admin_sort_url
]
else:
admin_urls = patterns('',
admin_do_sorting_url,
admin_sort_url,)
return admin_urls + urls return admin_urls + urls
def sort_view(self, request): def sort_view(self, request):

View File

@ -121,12 +121,12 @@ class SortableMixin(models.Model):
def get_next(self, extra_filters={}, filter_on_sortable_fk=True): def get_next(self, extra_filters={}, filter_on_sortable_fk=True):
return self._filter_objects( return self._filter_objects(
{'{0}__gt'.format(self.order_field_name): self._get_order_field_value}, {'{0}__gt'.format(self.order_field_name): self._get_order_field_value()},
extra_filters, filter_on_sortable_fk) extra_filters, filter_on_sortable_fk)
def get_previous(self, extra_filters={}, filter_on_sortable_fk=True): def get_previous(self, extra_filters={}, filter_on_sortable_fk=True):
return self._filter_objects( return self._filter_objects(
{'{0}__lt'.format(self.order_field_name): self._get_order_field_value}, {'{0}__lt'.format(self.order_field_name): self._get_order_field_value()},
extra_filters, filter_on_sortable_fk) extra_filters, filter_on_sortable_fk)

View File

@ -1,4 +1,10 @@
from django.contrib.contenttypes import generic from django import VERSION
if VERSION < (1, 9):
from django.contrib.contenttypes.generic import GenericForeignKey
else:
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db import models from django.db import models
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
@ -109,7 +115,7 @@ class GenericNote(SimpleModel, SortableMixin):
content_type = models.ForeignKey(ContentType, content_type = models.ForeignKey(ContentType,
verbose_name=u"Content type", related_name="generic_notes") verbose_name=u"Content type", related_name="generic_notes")
object_id = models.PositiveIntegerField(u"Content id") object_id = models.PositiveIntegerField(u"Content id")
content_object = generic.GenericForeignKey(ct_field='content_type', content_object = GenericForeignKey(ct_field='content_type',
fk_field='object_id') fk_field='object_id')
order = models.PositiveIntegerField(default=0, editable=False) order = models.PositiveIntegerField(default=0, editable=False)