Merge branch 'hostadmin-perf' into 'master'
Hostadmin perf very fast See merge request !2
This commit is contained in:
commit
9d737dcd45
5 files changed
+32
-9
No files matched your search
+2
-1
@@ -1,5 +1,5 @@
|
||||
from django.contrib import admin, messages
|
||||
|
||||
from mdb.forms import InterfaceForm
|
||||
from mdb.models import Ip6Address, Interface, Ip4Address, DhcpOption, DhcpCustomField, DomainSrvRecord, DomainTxtRecord, \
|
||||
DomainCnameRecord, DomainARecord, Domain, Host, Ip4Subnet, Ip6Subnet, Nameserver, MailExchange, OperatingSystem, \
|
||||
HostType, DhcpConfig, DomainAAAARecord
|
||||
@@ -14,6 +14,7 @@ class InterfaceInline(admin.TabularInline):
|
||||
inlines = [Ip6AddressInline]
|
||||
model = Interface
|
||||
extra = 0
|
||||
form = InterfaceForm
|
||||
|
||||
def get_queryset(self, request):
|
||||
return super(InterfaceInline, self).get_queryset(request).select_related()
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
from django import forms
|
||||
from django.forms import ModelChoiceField
|
||||
|
||||
from mdb.models import Interface, Ip4Address
|
||||
|
||||
|
||||
class Ip4ModelChoiceField(ModelChoiceField):
|
||||
def label_from_instance(self, obj):
|
||||
if not hasattr(obj, 'interface'):
|
||||
return obj.address
|
||||
|
||||
return "{} ({})".format(obj.address, obj.interface.host.hostname)
|
||||
|
||||
|
||||
class InterfaceForm(forms.ModelForm):
|
||||
model = Interface
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(InterfaceForm, self).__init__(*args, **kwargs)
|
||||
|
||||
# Join Ip4Address with tables interface and host,
|
||||
# before printing the select labels that walk those two relations.
|
||||
queryset = Ip4Address.objects.select_related('interface', 'interface__host')
|
||||
self.fields['ip4address'] = Ip4ModelChoiceField(queryset=queryset)
|
||||
+1
-5
@@ -472,11 +472,7 @@ class Ip4Address(models.Model):
|
||||
ping_avg_rtt = models.FloatField(null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
# FIXME: generates 2 SQL queries?
|
||||
if not hasattr(self, 'interface'):
|
||||
return self.address
|
||||
|
||||
return "{} ({})".format(self.address, self.interface.host.hostname)
|
||||
return self.address
|
||||
|
||||
def assigned_to_host(self):
|
||||
return self.interface.host
|
||||
|
||||
@@ -76,6 +76,7 @@ INSTALLED_APPS = (
|
||||
'django.contrib.admin',
|
||||
'rest_framework',
|
||||
'rest_framework.authtoken',
|
||||
'django_extensions',
|
||||
|
||||
'mdb',
|
||||
)
|
||||
|
||||
+4
-3
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mdb.settings")
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
import os
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mdbsite.settings")
|
||||
|
||||
application = get_wsgi_application()
|
||||
Reference in new issue
Block a user