In a loop and automatically, that is, I always check all users once every 10 minutes, and I may need to update a bool field from them How can I not change my current field when I update that bool field ?
class Client(models.Model):
user = models.ForeignKey ...
last_activity = models.DateTimeField(_("Last Activity"), auto_now=True)
joined = models.BooleanField(_("Joined in Default Channel"), default = False)
...
...
i want to update joined
field without change last_activity
.
how can i do?
If you have a Client
object, you can specify the fields to update with the update_fields=…
parameter of the .save(…)
method [Django-doc] of your model:
c1 = … # (some client)
c1.joined = True
c1.save(update_fields=['joined'])
If you want to update Client
s with a single query (or in bulk), you can work with .update(…)
[Django-doc]:
c1 = Client.objects.filter(pk=some_pk).update(
joined=True
)
DateTime field is updated when .save() method is called, you can update needed field(s) using .update method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With