journal: use EntryManager
This commit is contained in:
parent
b2ed0b5466
commit
74aaaab261
|
@ -19,7 +19,7 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, *args, **options):
|
||||
_, columns = os.popen("stty size", "r").read().split()
|
||||
for entry in reversed(Entry.objects.order_by('-timestamp')[:int(options['lines'])]):
|
||||
for entry in Entry.objects.print(lines=options['lines']):
|
||||
line = "%s %s %s" % (
|
||||
entry.timestamp.strftime("%c"),
|
||||
entry.host,
|
||||
|
|
|
@ -3,10 +3,16 @@ from django.contrib.postgres.fields import JSONField
|
|||
from django.contrib.postgres.indexes import GinIndex
|
||||
|
||||
|
||||
class EntryManager(models.Manager):
|
||||
def print(self, lines=100):
|
||||
return self.model.objects.order_by('-timestamp')[:int(lines)].reverse()
|
||||
|
||||
|
||||
class Entry(models.Model):
|
||||
timestamp = models.DateTimeField(auto_now_add=True, db_index=True)
|
||||
host = models.CharField(max_length=128, db_index=True)
|
||||
data = JSONField()
|
||||
objects = EntryManager()
|
||||
|
||||
def __str__(self):
|
||||
return '%s %s %s' % (self.timestamp, self.host, self.data)
|
||||
|
|
Reference in New Issue