2

AoA, I know the question is silly, but I am stuck here

here is the code...

nq = Notifications.objects.filter(userid__iexact=q)
    for string in nq:
            string.markType = "Read"
    results = Notifications.objects.filter(Q(userid__iexact=q)).order_by('-id')

but the markType failed to set to "Read" ... why?

1
  • 4
    You never called string.save(). Commented Nov 24, 2013 at 20:38

2 Answers 2

2

You probably meant to save the object after changing it:

nq = Notifications.objects.filter(userid__iexact=q)
for string in nq:
    string.markType = "Read"
    string.save()
results = Notifications.objects.filter(Q(userid__iexact=q)).order_by('-id')
Sign up to request clarification or add additional context in comments.

1 Comment

I told you that it was a silly question thanks for your help :)
2

Apart from the fact that you forgot to save your object it is recommended to use queryset.update method here, it is going to be faster than your current approach. But in case you've overrided the save method then don't use it.:

Notifications.objects.filter(userid__iexact=q).update(markType = "Read")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.