models.py 1.32 KB
# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from django.db.models import Model, CharField, DateTimeField, ForeignKey, \
    TextField, IntegerField

from dictionary.models import Lexeme
from patterns.models import Pattern


class HistoryFrame(Model):
    transaction_began = DateTimeField(db_index=True)
    lexeme = ForeignKey(Lexeme, null=True, blank=True)
    pattern = ForeignKey(Pattern, null=True, blank=True)
    user = ForeignKey(User)


class History(Model):
    frame = ForeignKey(HistoryFrame, null=True)
    table_name = CharField(max_length=120, db_column='table_name_')
    column_name = CharField(
        max_length=120, db_column='column_name_', blank=True)
    timestamp = DateTimeField(db_column='timestamp_')
    old_value = TextField(db_column='old_value_', blank=True)
    new_value = TextField(db_column='new_value_', blank=True)
    row_id = IntegerField(db_column='id_')
    operation = CharField(max_length=120, db_column='operation_')
    table_oid = IntegerField(db_column='table_oid_')
    column_ord = IntegerField(db_column='ordinal_position_of_column_')

    def __unicode__(self):
        return '%s %s.%s %s -> %s' % (
            self.operation, self.table_name, self.column_name,
            repr(self.old_value),
            repr(self.new_value))

    class Meta:
        db_table = 'history'