I'm running into a problem with using a flag to mark model instances for future processing. I have a class:
class MyModel(models.Model):
processed = models.BooleanField(default=False)
changed = models.DateTimeField(auto_now=True)
# More fields.
def save(self):
self.processed = False
super().save(*args, **kwargs)
Then I have a management command:
class Command(BaseCommand):
def handle(self, *args: Any, **kwargs: Any) -> None:
models = MyModel.objects.filter(processed=False).order_by("changed")[:200]
for model in models:
# Do some processing
model.processed = True
model.save()
Now, obviously when the model is saved, it's just going to re-mark the instance as unprocessed.
I'm new to django, so my knowledge of the model lifecycle and the available methods is pretty limited. I've been reading through the documentation and haven't found any solution so far.
Any ideas on how I could tackle this?