Newer order values voilates the field rule of PositiveIntegerField
a8568730 opened this issue · 11 comments
Thank you for this project, it's easy to use and helpful. :)
We follow the instruction of Prepare the Model Classes to implement a PositiveIntegerField in our model to record the order.
But we got the POST error:
Invalid POST request: new row for relation "sutian_所在" violates check constraint "sutian_所在_先後_check"
DETAIL: Failing row contains (10, 臺中偏漳腔, -1).
We have the version:
- Version of django-admin-sortable2: 2.1.4
- Version of Python: 3.9.5
- Version of Django: 4.0.10
Our models.py:
class Location(models.Model):
place = models.CharField(
max_length=20,
unique=True,
help_text="鹿港、三峽、臺北、宜蘭、……",
)
my_order = models.PositiveIntegerField(
default=0
)
We found the updateditems
in request sometimes contain negative numbers, like:
{
"updatedItems": [
[
"9",
0
],
[
"10",
-1
]
]
}
So it violates the rules of PositiveIntegerField.
I have the same issue when updating to django 4.2.3, grapelli 3.0.6 and python 3.11, all items seem to have their order set to zero and when the reordering happens it writes negative values to the items and throws an error
Same problem with django 4.2.3 and python 3.11, first time trying to use this.
I fresh added a field as a PositiveIntegerField setting default to 0 and no matter what I try to reorder it always set - values.
Did you read the contribution guidelines, and try to reproduce this alleged bug there?
Sorry currently having not much time, I did a quick debug on that one, and it is the javascript part assigning minus numbers as the new order, looks like it has a problem if all order values are 0, just setting a single one to 1 fixed the problem.
@jrief Thank you for reminding me the contribution guidelines, I will find some time build the client, run the demo and fix my report.
I did everything as indicated in the installation instructions. And met the same error. Sorting does not work with PositiveIntegerField. Replacing it with IntegerField solved my problem. Works great, thanks.
{ "count": 2, "results": [ { "id": "test", "name": "test", "type": "product", "parent": null, "order": 0 }, { "id": "test2", "name": "test2", "type": "product", "parent": "odyag", "order": -1 } ] }
@jrief Yes, problem is order field can be negative number or zero. So PositiveIntegerField cannot work with it. Even if I tried use 1000 as default value, next reorder request tries to set -1 for target object. You can see it in my example above.
did you try with the examples provided in folder testapp/
?
The demo models in testapp/
all use a PositiveIntegerField
. So it seems that something is broken in your setup.
I just encountered the same issue. My mistake was not reading the paragraph Initial data at the bottom of the documentation.