Skip to content

Instantly share code, notes, and snippets.

@caot
Last active March 26, 2023 17:42
Show Gist options
  • Select an option

  • Save caot/f07118eb76167bbd6f8454c9e6640ded to your computer and use it in GitHub Desktop.

Select an option

Save caot/f07118eb76167bbd6f8454c9e6640ded to your computer and use it in GitHub Desktop.
>>> from django.contrib.auth.models import User
>>> ContentType.objects.get_for_model(User)
<ContentType: user>
from django.contrib.contenttypes.models import ContentType
from auditlog.models import LogEntry
import json
def get_LogEntry_Journal(self, model, field_name):
content_type = ContentType.objects.get_for_model(model)
d = {}
try:
obj = LogEntry.objects.filter(content_type=content_type).latest('timestamp')
except Exception as _e:
return d
logging.debug([obj.timestamp, obj.timestamp.date(), obj, ])
objs = LogEntry.objects.filter(content_type=contenttype, timestamp__date=obj.timestamp.date())
for o in objs:
x = json.loads(o.changes)
# logging.debug([type(x), x, o.timestamp])
v = x.get(field_name, [])
v_1 = staging_phase[1]
if len(staging_phase) == 2 and v_1 == 'P':
d.update({int(o.object_id): v_1})
# logging.debug(d)
return d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment