misc: prefill tenant choices
This commit is contained in:
parent
f8db9f3cfe
commit
740a2836e6
|
@ -16,3 +16,4 @@ class EntriesForm(forms.Form):
|
|||
super().__init__(*args, **kwargs)
|
||||
self.fields['host'].choices = set([(e, e) for e in Entry.objects.hosts()])
|
||||
self.fields['_systemd_unit'].choices = [(e, e) for e in Entry.objects.units()]
|
||||
self.fields['tenant'].choices = [(e, e) for e in Entry.objects.tenants()]
|
||||
|
|
|
@ -50,6 +50,14 @@ class EntryManager(models.Manager):
|
|||
cache.set('units', value, 600 * random.random())
|
||||
return value
|
||||
|
||||
def tenants(self):
|
||||
value = cache.get('tenants')
|
||||
if value is None:
|
||||
value = sorted([v for v in self.model.objects.all().annotate(unit=KeyTextTransform('TENANT', 'data')).values_list('unit', flat=True).distinct() if v], key=lambda x: x.lower())
|
||||
cache.set('tenants', value, 600 * random.random())
|
||||
return value
|
||||
|
||||
|
||||
|
||||
class Entry(models.Model):
|
||||
timestamp = models.DateTimeField(db_index=True)
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
<form action="." style="display:inline;">
|
||||
{{ form.as_table }}
|
||||
<input type="submit" value="Filter" />
|
||||
<br/><input type="submit" value="Filter" />
|
||||
</form>
|
||||
|
||||
<table>
|
||||
|
|
Reference in New Issue