Home > Back-end >  How to keep values from a queryset?
How to keep values from a queryset?

Time:01-14

I have a problem with an update function. I make a queryset to get some objects that I store in a variable. I make some modifications in the base. I do the same queryset again and store it in another variable.

The result of my 2 querysets are not equal, but the 2 variables are.

def update(self, instance, validated_data):
        old_priorities = DiscountPriority.objects.filter(machine__in=instance.machines.all())
        print(old_priorities)
        # <QuerySet [<DiscountPriority: Priority 1 of a13 on dzafezfdezaaaa>, <DiscountPriority: Priority 1 of a13 on test19>]>
        response = super(DiscountSerializer, self).update(instance, validated_data)
        
        current_priorities = DiscountPriority.objects.filter(machine__in=instance.machines.all())
        print(current_priorities)
        # <QuerySet [<DiscountPriority: Priority 1 of a13 on dzafezfdezaaaa>]>
        print(old_priorities)
        # <QuerySet [<DiscountPriority: Priority 1 of a13 on dzafezfdezaaaa>]>

CodePudding user response:

Your querysets are retrieving the same objects.. That's what matters.

It is still the same object. Objects are identified by their primary keys

  •  Tags:  
  • Related