Version bump to 2.1.9
Updated readme. Added filter_kwargs as a replacement to extra_filters.master
parent
fabd78e5be
commit
b1258afcea
17
README.md
17
README.md
|
|
@ -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 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
|
## 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)
|
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
|
```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
|
### Adding Sorting to an existing model
|
||||||
|
|
||||||
#### Django 1.5.x to 1.6.x
|
#### 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
|
### Status
|
||||||
django-admin-sortable is currently used in production.
|
django-admin-sortable is currently used in production.
|
||||||
|
|
||||||
### What's new in 2.1.8?
|
### What's 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
|
### 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.
|
- Better template support for foreign keys that are self referential. If someone would like to take on rendering recursive sortables, that would be super.
|
||||||
|
|
|
||||||
19
README.rst
19
README.rst
|
|
@ -42,7 +42,7 @@ the new tuple-based format if you haven’t already.
|
||||||
|
|
||||||
django-admin-sortable 1.7.1 and higher are compatible with Python 3.
|
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
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
@ -302,12 +302,19 @@ If you wish to override this behavior, pass in:
|
||||||
|
|
||||||
your_instance.get_next(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,
|
You may also pass in additional ORM "filer_args" as a list, or "filter_kwargs" as a dictionary, should you need to:
|
||||||
should you need to:
|
|
||||||
|
|
||||||
.. code:: python
|
.. 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
|
Adding Sorting to an existing model
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
@ -731,10 +738,10 @@ Status
|
||||||
|
|
||||||
django-admin-sortable is currently used in production.
|
django-admin-sortable is currently used in production.
|
||||||
|
|
||||||
What’s new in 2.1.8?
|
What’s 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
|
Future
|
||||||
~~~~~~
|
~~~~~~
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
VERSION = (2, 1, 8)
|
VERSION = (2, 1, 9)
|
||||||
DEV_N = None
|
DEV_N = None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,10 +100,15 @@ class SortableMixin(models.Model):
|
||||||
|
|
||||||
super(SortableMixin, self).save(*args, **kwargs)
|
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:
|
if extra_filters:
|
||||||
filters.update(extra_filters)
|
filters.update(extra_filters)
|
||||||
|
|
||||||
|
if filter_kwargs:
|
||||||
|
filters.update(filter_kwargs)
|
||||||
|
|
||||||
if self.sortable_foreign_key and filter_on_sortable_fk:
|
if self.sortable_foreign_key and filter_on_sortable_fk:
|
||||||
# sfk_obj == sortable foreign key instance
|
# sfk_obj == sortable foreign key instance
|
||||||
sfk_obj = getattr(self, self.sortable_foreign_key.name)
|
sfk_obj = getattr(self, self.sortable_foreign_key.name)
|
||||||
|
|
@ -119,17 +124,23 @@ class SortableMixin(models.Model):
|
||||||
|
|
||||||
return obj
|
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(
|
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()},
|
||||||
filter_args,
|
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(
|
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()},
|
||||||
filter_args,
|
filter_args,
|
||||||
extra_filters, filter_on_sortable_fk)
|
extra_filters,
|
||||||
|
filter_kwargs,
|
||||||
|
filter_on_sortable_fk
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# for legacy support of existing implementations
|
# for legacy support of existing implementations
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue