Saturday, January 8, 2022

Request result update only if I change even one character... Strange... :s

Hello to all of you,

I have a very strange behavior that I do not understand and that I will try to explain here:

Global situation: School management website.

Expected comportment: User show student amout: 10. User Add 5, return to app, pull down to refresh and see 15.

Actual comportment: User show student amout: 10. User Add 5, return to app, pull down to refresh and see 10.

Fix: I change only on char in my code (even a space, a letter, a tab or anything else), the manage.py runserver reload, i pull down to refresh and see 15.

If i put the code of the function that calculate the total amount direct in the method user in the request, all is good. :/

Totaly incomprehensible :s

Details:
- I have 2 applications: One manages students, another manages payments for them.
- In my payment model, I have this function :
class Payment(SoftDeleteObject, models.Model):
    amount = models.FloatField()
    ...

    @staticmethod
    def get_total_payments(wallet_reference=False, date=timezone.datetime.now()):
        """"
        Get total payment from wallet reference and from a date
        @param wallet_reference:
        @param date:
        @return:
        """
        payments = Payment.objects.filter(
                Q(wallet_reference=wallet_reference),
                Q(payment_date__lte=date),
                Q(status=PAYMENT_STATUS['SUCCEEDED'])
        )
        total_payment = 0
        for payment in payments:
                total_payment += payment.amount
        return total_payment

- In my payment application, I use this function when I make a request to find the total available, the total consumed, etc... like this:

class ListStudentPayment(generics.GenericAPIView):

    def get(self, *args, **kwargs):
        today = timezone.now().date()
        student = Student.objects.get(pk=kwargs['student_id'])
       .... 
        total_payment = Payment.get_total_payments(student.wallet_reference)

- This function is called right after a stripe payment, to refresh my student's balance in the application.

Do you have an explaination ?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3c7bcb96-cb00-48bb-9206-0ac1bcaa960cn%40googlegroups.com.

No comments:

Post a Comment