大家好,我是Django的新手,直到现在我使用简单模型和通用视图。
现在我有两个模型,Server
和InventaryGroups
,其中InventoryGroups
是Servers
的组。
class Server(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField(max_length=20, null=True)
hostname = models.CharField(max_length=50, null=True, blank=True)
ip = models.GenericIPAddressField()
ip2 = models.GenericIPAddressField(null=True, blank=True)
user_name = models.CharField(max_length=20, null=True)
password = models.CharField(max_length=200, null=True, blank=True)
ssh_key = models.FileField(null=True, blank=True)
status = models.CharField(max_length=10, null=True, blank=True)
last_login_time = models.DateTimeField(null=True, blank=True)
last_login_from = models.GenericIPAddressField(null=True, blank=True)
def __str__(self):
return str(self.user) + " - " + self.name
class InventoryGroups(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField(max_length=20, null=True)
host = models.ManyToManyField(Server)
description = models.CharField(max_length=100, null=True, blank=True)
def get_hosts(self):
if self.host:
hostlist = []
for name in self.host.all():
hostlist.append(name)
return hostlist
def __str__(self):
return str(self.user) + " - " + self.name
我要做的是根据Server
限制我的User
(服务器列表)。像这样:
您可以在主机列表中查看所有服务器。
但我想只显示由Severs
InventoryGroups.user
个 int numberOfItems = 100000;
int[] array = new int[numberOfItems];
int count = 0;
for (int i = numberOfItems / 2; i > 0; i--)
{
array[count++] = i;
}
for (int i = 0; i < numberOfItems / 2; i++)
{
array[count++] = i;
}