Commit 5d3994cd authored by Damien Lespiau's avatar Damien Lespiau
Browse files

patch: Add a last_updated field



Just like with series, it's handy to be able to query patches that have
changed since the last time we looked.

The migration is a bit complicated as we need to populate the initial
value of that field, ensuring the invariant that this field cannot be
NULL.
Signed-off-by: default avatarDamien Lespiau <damien.lespiau@intel.com>
parent 11c561e5
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
def set_auto_now(obj, field_name, enable):
for field in obj._meta.local_fields:
if field.name == field_name:
field.auto_now = enable
def noop(apps, schema_editor):
pass
def set_patch_last_updated(apps, schema_editor):
Patch = apps.get_model("patchwork", "Patch")
query = Patch.objects.all()
for _, patch in enumerate(query.iterator()):
patch.last_updated = patch.date
set_auto_now(patch, "last_updated", False)
patch.save()
set_auto_now(patch, "last_updated", True)
class Migration(migrations.Migration):
dependencies = [
('patchwork', '0024_blank_test_state'),
]
operations = [
migrations.AddField(
model_name='patch',
name='last_updated',
field=models.DateTimeField(auto_now=True, null=True),
),
migrations.RunPython(set_patch_last_updated, noop),
migrations.AlterField(
model_name='patch',
name='last_updated',
field=models.DateTimeField(auto_now=True),
),
]
......@@ -301,6 +301,7 @@ class Patch(models.Model):
msgid = models.CharField(max_length=255)
name = models.CharField(max_length=255)
date = models.DateTimeField(default=datetime.datetime.now)
last_updated = models.DateTimeField(auto_now=True)
submitter = models.ForeignKey(Person)
delegate = models.ForeignKey(User, blank=True, null=True)
state = models.ForeignKey(State, null=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment