jpwatts / django-positions

A Django field for custom model ordering.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Changing position and collection foreign key simlutaneously does not work

Krystofee opened this issue · comments

models.py

class Item(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True)
    container = models.ForeignKey(to=Container)
    position = PositionField(collection='container')

class Container(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True)
    ...

django shell:

>>> container1 = Container.objects.create(...)
>>> item1 = Item.objects.create(container=container1)
>>> item2 = Item.objects.create(container=container1)
>>> container2 = Container.objects.create(...)
>>> item1.container = container2
>>> item1.position = 1

I've tried to debug the code and figured out that:

in fields.py (229 - update_on_save)

        current, updated = getattr(instance, self.get_cache_name())

the value of current is None and it gets compared to the int and I'm getting an error.