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
"""
STATUS_TYPE = (
('1', 'NORMAL'),
('2', 'DELETE'),
('3', 'DISABLE')
)
create_time = models.DateTimeField('create_time', default=datetime.now)
update_time = models.DateTimeField('update_time', default=datetime.now)
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
SystemUserLogMixin.log_delete(self)

# override delete method
self.delete_time = datetime.now()
self.data_status = '2'
self.save()

def save(self, *args, **kw):
log = SystemUserLogMixin()
is_insert = False
if self.id:
# update
print('update model')
# logging update
log.log_update(model=self)
else:
# 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
log.log_create(model=self)

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

class Meta:
abstract = True


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

Project details


Download files

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

Source Distribution

simple-model-logging-1.1.3.tar.gz (5.0 kB view details)

Uploaded Source

File details

Details for the file simple-model-logging-1.1.3.tar.gz.

File metadata

File hashes

Hashes for simple-model-logging-1.1.3.tar.gz
Algorithm Hash digest
SHA256 15cf2e3bfde62f9d7dce24c95dfebb2212576e6d831e4c04a688cbd2f9ce50ac
MD5 448aeb912bb86f5edb12d53f1121f4b9
BLAKE2b-256 fc29fca845a537c397fd94bbba6c05d5f28508a03d4101dcd97789d5f5309d77

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page