Skip to content

Commit

Permalink
Create base model with created_at and is_deleted fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
lydiagu committed Apr 14, 2016
1 parent d8b3fa7 commit b25f54a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
26 changes: 26 additions & 0 deletions orchestra/migrations/0037_add_fields_to_iteration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-04-14 21:18
from __future__ import unicode_literals

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('orchestra', '0036_remove_taskassignment_snapshots'),
]

operations = [
migrations.AddField(
model_name='iteration',
name='created_at',
field=models.DateTimeField(default=django.utils.timezone.now),
),
migrations.AddField(
model_name='iteration',
name='is_deleted',
field=models.BooleanField(default=False),
),
]
3 changes: 2 additions & 1 deletion orchestra/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from jsonfield import JSONField

from orchestra.core.errors import ModelSaveError
from orchestra.utils.models import BaseModel

# TODO(marcua): Convert ManyToManyFields to django-hstore referencefields or
# wait for django-postgres ArrayFields in Django 1.8.
Expand Down Expand Up @@ -443,7 +444,7 @@ def __str__(self):
str(self.task), self.assignment_counter, str(self.worker))


class Iteration(models.Model):
class Iteration(BaseModel):
"""
Iterations are the contiguous units of a worker's time on task.
Expand Down
26 changes: 26 additions & 0 deletions orchestra/utils/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.db import models
from django.utils import timezone


class DeleteMixin(object):

def delete(self, *args, **kwargs):
self.is_deleted = True
self.save()


class BaseModel(DeleteMixin, models.Model):
"""
Abstract base class models which defines created_at and is_deleted fields.
Attributes:
created_at (datetime.datetime):
Datetime at which the model is created.
is_deleted (boolean):
If value is True, TimeEntry is deleted. Default is False.
"""
created_at = models.DateTimeField(default=timezone.now)
is_deleted = models.BooleanField(default=False)

class Meta:
abstract = True

0 comments on commit b25f54a

Please sign in to comment.