Version bump to 2.1.9

Updated readme.
Added filter_kwargs as a replacement to extra_filters.
master
Brandon Taylor 2018-10-10 14:02:11 -04:00
parent fabd78e5be
commit b1258afcea
4 changed files with 42 additions and 17 deletions

View File

@ -30,7 +30,7 @@ django-admin-sortable 1.6.6 introduced a backward-incompatible change for the `s
django-admin-sortable 1.7.1 and higher are compatible with Python 3.
django-admin-sortable 2.1.6 ihas a bug. Please don't use it :)
django-admin-sortable 2.1.6 has a bug. Please don't use it :)
## Installation
@ -242,12 +242,19 @@ If you wish to override this behavior, pass in: `filter_on_sortable_fk=False`:
your_instance.get_next(filter_on_sortable_fk=False)
```
You may also pass in additional ORM "extra_filters" as a dictionary, should you need to:
You may also pass in additional ORM "filer_args" as a list, or "filter_kwargs" as a dictionary, should you need to:
```python
your_instance.get_next(extra_filters={'title__icontains': 'blue'})
your_instance.get_next(
filter_args=[Q(field1=True) | Q(field2=True)],
filter_kwargs={'title__icontains': 'blue'}
)
```
#### Deprecation Warning
Previously "filter_kwargs" was named "extra_filters". With the addition of "filter_args", "extra_filters" was renamed for consistency. "extra_filters" will be removed in the next version of django-admin-sortable.
### Adding Sorting to an existing model
#### Django 1.5.x to 1.6.x
@ -599,8 +606,8 @@ ordering on top of that just seemed a little much in my opinion.
### Status
django-admin-sortable is currently used in production.
### What's new in 2.1.8?
- Bug fix for sorting a queryset where a search may have been performed.
### What's new in 2.1.9?
- get_next() and get_previous() methods now accept filter arguments as a list to support Q objects.
### Future
- Better template support for foreign keys that are self referential. If someone would like to take on rendering recursive sortables, that would be super.

View File

@ -42,7 +42,7 @@ the new tuple-based format if you havent already.
django-admin-sortable 1.7.1 and higher are compatible with Python 3.
django-admin-sortable 2.1.6 ihas a bug. Please dont use it :)
django-admin-sortable 2.1.6 has a bug. Please dont use it :)
Installation
------------
@ -302,12 +302,19 @@ If you wish to override this behavior, pass in:
your_instance.get_next(filter_on_sortable_fk=False)
You may also pass in additional ORM “extra_filters” as a dictionary,
should you need to:
You may also pass in additional ORM "filer_args" as a list, or "filter_kwargs" as a dictionary, should you need to:
.. code:: python
your_instance.get_next(extra_filters={'title__icontains': 'blue'})
your_instance.get_next(
filter_args=[Q(field1=True) | Q(field2=True)],
filter_kwargs={'title__icontains': 'blue'}
)
Deprecation Warning
^^^^^^^^^^^^^^^^^^^^^
Previously "filter_kwargs" was named "extra_filters". With the addition of "filter_args", "extra_filters" was renamed for consistency. "extra_filters" will be removed in the next version of django-admin-sortable.
Adding Sorting to an existing model
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -731,10 +738,10 @@ Status
django-admin-sortable is currently used in production.
Whats new in 2.1.8?
Whats new in 2.1.9?
~~~~~~~~~~~~~~~~~~~~
- Bug fix for sorting a queryset where a search may have been performed.
- get_next() and get_previous() methods now accept filter arguments as a list to support Q objects.
Future
~~~~~~

View File

@ -1,4 +1,4 @@
VERSION = (2, 1, 8)
VERSION = (2, 1, 9)
DEV_N = None

View File

@ -100,10 +100,15 @@ class SortableMixin(models.Model):
super(SortableMixin, self).save(*args, **kwargs)
def _filter_objects(self, filters, filter_args, extra_filters, filter_on_sortable_fk):
def _filter_objects(self, filters, filter_args, extra_filters, filter_kwargs, filter_on_sortable_fk):
# DEPRECATION WARNING: `extra_filters` will be replaced by `filter_kwargs` in the next release
if extra_filters:
filters.update(extra_filters)
if filter_kwargs:
filters.update(filter_kwargs)
if self.sortable_foreign_key and filter_on_sortable_fk:
# sfk_obj == sortable foreign key instance
sfk_obj = getattr(self, self.sortable_foreign_key.name)
@ -119,17 +124,23 @@ class SortableMixin(models.Model):
return obj
def get_next(self, filter_args=[], extra_filters={}, filter_on_sortable_fk=True):
def get_next(self, filter_args=[], extra_filters={}, filter_kwargs={}, filter_on_sortable_fk=True):
return self._filter_objects(
{'{0}__gt'.format(self.order_field_name): self._get_order_field_value()},
filter_args,
extra_filters, filter_on_sortable_fk)
extra_filters,
filter_kwargs,
filter_on_sortable_fk
)
def get_previous(self, filter_args=[], extra_filters={}, filter_on_sortable_fk=True):
def get_previous(self, filter_args=[], extra_filters={}, filter_kwargs={}, filter_on_sortable_fk=True):
return self._filter_objects(
{'{0}__lt'.format(self.order_field_name): self._get_order_field_value()},
filter_args,
extra_filters, filter_on_sortable_fk)
extra_filters,
filter_kwargs,
filter_on_sortable_fk
)
# for legacy support of existing implementations