jpwatts / django-positions

A Django field for custom model ordering.
BSD 3-Clause "New" or "Revised" License
284 stars 71 forks source link

cannot save model with set position #5

Closed Uznick closed 14 years ago

Uznick commented 14 years ago

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?

jpwatts commented 14 years ago

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 17a1f50729b6f14c0dd52bddd17d61ec5de6ff11.

Thanks for the report.