I've created project for managing virtual machines via libvirt using django
few years ago. Also you can take a look at ganeti project. I'm ready to
answer any question related to django and cloud computing.

Thanks, Serge

20 серп. 2016 20:23 "Wolf Painter" <w...@dorkbrigade.com> пише:

> If you look at the code for the template, images is in there. I've tried
> all the ways I found to display my multidimensional dictionary, one of
> which is to loop through the first part, then the second. If you look at
> the code below, I'm looping through the first part of the dictionary, then
> the second by calling the value on child_list.items which is images. So
> far, nothing I've tried is working no matter how I loop through it in the
> template. I'm still stuck on this as nothing I have looked up has worked,
> but I am new to django, so there may be something I'm missing.:
>
> {% for server, images in child_list.items %}
>     <h1>{{ server }}</h1>
>     {% for image, number in images.items %}
>         <h1>{{ number }}</h1>
>     {% endfor %}
> {% endfor %}
>
>
> On Thursday, August 18, 2016 at 6:33:58 AM UTC-7, Derek wrote:
>>
>> In your view you have:
>>
>>     context = {
>>         "server_list": serverlist,
>>         "image_list": imagelist,
>>         "child_list": childimagelist
>>     }
>>
>> So the variables being passed through to your template are named:
>> server_list, image_list, child_list.
>>
>> In your template you call this:
>>
>>     for server, images in child_list.items
>>
>> Which is fine, but then you call this:
>>
>>     for image, number in images.items
>>
>> But there is no variable called "images".... I think it should be
>> "image_list:.
>>
>> HTH
>> Derek
>>
>>
>> On Tuesday, 16 August 2016 02:22:28 UTC+2, Wolf Painter wrote:
>>>
>>> Hey everyone, I didn't see any posts (or google search) that could
>>> possibly answer my question, so I am here... I'm trying to create a way to
>>> launch vm's on a Xen or VMWare server using a website. I have the python
>>> file written on the Server and am currently creating a DJango app to manage
>>> everything. I'm stuck in a big way. I  currently have models that track
>>> servers, images and child images launched from the parent, but I can't
>>> figure out how to display it properly in a template so i can update the
>>> count (either add or subtract a number of VM's from a server). I'm new to
>>> both Django and Python, so please excuse any ignorance here... Here are my
>>> relevant models:
>>>
>>> class Image(models.Model):
>>>     name = models.CharField(verbose_name='Image Name', max_length=50)
>>>     labID = models.ManyToManyField(Lab, blank=True, related_name='labID')
>>>     type = models.CharField(max_length=50)
>>>
>>>     def __str__(self):
>>>         return self.name
>>>
>>>
>>> class Server(models.Model):
>>>     name = models.CharField(verbose_name='Server Name', max_length=50)
>>>     ipAddress = models.CharField(max_length=15)
>>>     maxCCU = models.IntegerField(default=0)
>>>     images = models.ManyToManyField(Image, blank=True, 
>>> related_name='baseImage')
>>>
>>>     def __str__(self):
>>>         return self.ipAddress
>>>
>>> class Childimage(models.Model):
>>>     name = models.CharField(verbose_name='Child Image Name', max_length=50)
>>>     parent = models.ForeignKey(Image, related_name='base')
>>>     server = models.ForeignKey(Server, related_name='server')
>>>     inUse = models.BooleanField()
>>>     rdpportnum = models.CharField(max_length=4)
>>>
>>>     def __str__(self):
>>>         return self.name
>>>
>>> What I'm trying to do is have a web page that displays the number of parent 
>>> images on a server by counting the child image. For example, I have a 
>>> parent image called win2k12_excel and there are 12 child images of the 
>>> parent win2k12_excel on the x.x.x.x server. I would like a web page that 
>>> shows there are 12 win2k12_excel images on that server that would allow me 
>>> to add or subtract the number on that server.
>>>
>>>
>>> I have created a view that does this and puts it into a multidimensional 
>>> dictionary, but I cannot figure out how to get that to render properly in a 
>>> template. Here is my view:
>>>
>>>
>>> def servers(request):
>>>     serverlist = Server.objects.all()
>>>     imagelist = Image.objects.filter(baseImage__in=serverlist).distinct()
>>>
>>>     childimagelist = defaultdict(list)
>>>     for server in serverlist:
>>>         for image in imagelist:
>>>             number = 
>>> Childimage.objects.filter(parent__name__contains=image).filter(server__ipAddress__contains=server).count()
>>>             childimagelist[server].append({image: number})
>>>     childimagelist.default_factory = None
>>>     context = {
>>>         "server_list": serverlist,
>>>         "image_list": imagelist,
>>>         "child_list": childimagelist
>>>     }
>>>     return render(request, "administration/servers.html", context)
>>>
>>> No matter what I have tried so far, I cannot get this dictionary to render 
>>> in a template. Is there a better way to do what I'm trying to do? Is there 
>>> a proper way to get the dictionary parsed in the template? Any help would 
>>> be appreciated.
>>>
>>>
>>> Oh, and I have search Google for weeks and tried all the suggestions I 
>>> found. None of them worked. I can get the first part of the dictionary 
>>> parsed, but no further than that. Here is the template code (server works, 
>>> but for image, number in images.items, does not):
>>>
>>>
>>> {% for server, images in child_list.items %}
>>>     <h1>{{ server }}</h1>
>>>     {% for image, number in images.items %}
>>>         <h1>{{ number }}</h1>
>>>     {% endfor %}
>>> {% endfor %}
>>>
>>>
>>>
>>> Any help at all would be appreciated...
>>>
>>>
>>> Thanks,
>>>
>>> Wolf
>>>
>>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/d855fdde-6a52-48d9-9a87-02beadf59be7%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/d855fdde-6a52-48d9-9a87-02beadf59be7%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADTRxJOwDmjfYwtd8hEcq1qzFiGEOoSx0Em1eZXgH%3DVD_aQ_0g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to