Skip to main content

Based Django 2.0.4 to logging update

Project description

based Django 2.x to logging model instances update

## Installation

`pip install simple-model-logging`

Add `simple-model-logging` to your `INSTALLED_APPS`.

## Usage

#### Low-level use

from datetime import datetime

from django.db import models

from .simple_model_logging import SystemUserLogMixin

class AbstractModel(models.Model):
base model
('1', 'NORMAL'),
('2', 'DELETE'),
('3', 'DISABLE')
create_time = models.DateTimeField('create_time',
update_time = models.DateTimeField('update_time',
update_time = models.DateTimeField('update_time', default=None, null=True, blank=True)
data_status = models.CharField('data_status', max_length=1, choices=STATUS_TYPE, default='1')

def delete(self, using=None, keep_parents=False):
# logging delete

# override delete method
self.delete_time =
self.data_status = '2'

def save(self, *args, **kw):
log = SystemUserLogMixin()
is_insert = False
# update
print('update model')
# logging update
# insert
# set insert signal
is_insert = True
print('insert model')

super(AbstractModel, self).save(*args, **kw)
if is_insert:
# logging insert
# this code can get the record id

def create(self, *args, **kw):
log = SystemUserLogMixin()
super(AbstractModel, self).create(*args, **kw)

class Meta:
abstract = True

class Person(AbstractModel):
bussiness model extends from AbstractModel.
when invoke the model's save(),create(),delete() method will do logging

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for simple-model-logging, version 1.1.3
Filename, size File type Python version Upload date Hashes
Filename, size simple-model-logging-1.1.3.tar.gz (5.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page