jpwatts / django-positions

A Django field for custom model ordering.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot save model with set position

Uznick opened this issue · comments

I have a simple model and a simple form

class SimleModel(models.Model):
    name = models.CharField(max_length = 100)
    position = PositionField(collection=('name',))

class SimpleForm(ModelForm):
    class Meta:
        model = SimpleModel
        fields = ['name']

When I populate the form and set position for it's instance, like:

form  = SimpleForm(request.POST)
form.instance.position = -2
result = form.save()

The models is saved to db, but position of record is last, not -2.
And after
result.position = -2
result.save()
everything is ok, but it's extra step, is it really needed?

My code wasn't doing the right thing for new instances if their position value was changed after initialization but before saving for the first time. That should no longer be the case as of 17a1f50.

Thanks for the report.