Discussion:
Human Readable Values
Mike Sacauskis
2018-11-26 23:36:13 UTC
Permalink
[image: Screenshot.png]
Hi

I'm new to DJango and have a question about how to display some model data
in a human readable form. I have three fields, one is an IP Address
<django.db.models.fields.IPAddressField> and two are
<django.db.models.fields.IntegerField>. When I render the template I get
the class name but no values. How do I render the values?

Thanks

Mike
--
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+***@googlegroups.com.
To post to this group, send email to django-***@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/e3067097-f156-43a9-9821-abda50b08b72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Nelson Varela
2018-11-27 13:15:12 UTC
Permalink
show your code that renders the values
--
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+***@googlegroups.com.
To post to this group, send email to django-***@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/bed468b7-eed5-4b57-a060-eef1793795a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Mike Sacauskis
2018-11-29 20:29:51 UTC
Permalink
Post by Nelson Varela
show your code that renders the values
This is the class

class Hardware(models.Model):
hardware_id = models.AutoField(primary_key=True)
compute_asset_name = models.TextField(blank=False, null=False)
hardware_type =
models.ForeignKey('HardwareAssetType',on_delete=models.CASCADE)
project_id = models.ForeignKey('Project',on_delete=models.CASCADE)
ipaddress = models.IPAddressField
macaddress = models.CharField(max_length=16)
version_number = models.CharField(max_length=128)
enginering_build = models.BooleanField
service_tag = models.CharField(max_length=128)
serial_number = models.CharField(max_length=128)
cpu_type = models.CharField(max_length=128)
cores = models.IntegerField
ramGB = models.IntegerField

def __str__(self):
return self.compute_asset_name

This is the template
{% extends 'labmanager/BasePage.html' %}
{% load labmanager_filters %}
{% block title %}Lab Assets{% endblock %}

{% block content %}
{% if user.is_authenticated %}
<title>Hardware Page</title>
<form action="{% url 'labmanager:HardwarePage' %}" method='post'>
<table align='center' border="1" cellspacing="0" cellpadding="0"
bordercolor="#00338e" >
<tr bgcolor="#00338e" >
<td><b><font color="#ffffff">Hardware Item</font></b></td>
<td><b><font color="#ffffff">Asset</font><b></td>
</tr>

<tr align="center">

<td >
Compute Asset Name
</td>
<td><p> {{ hardware.compute_asset_name }} </p> </td>
</tr>

<tr align="center">

<td >
Hardware Type
</td>
<td><p> {{ hardware.hardware_type }} </p> </td>
</tr>

<tr align="center">

<td >
IP Address
</td>
<td><p> {{ hardware.ipaddress }} </p> </td>
</tr>
<tr align="center">

<td >
MAC Address
</td>
<td><p> {{ hardware.macaddress }} </p> </td>
</tr>

<tr align="center">

<td >
Version Number
</td>
<td><p> {{ hardware.version_number}} </p> </td>
</tr>

<tr align="center">

<td >
Release Type
</td>
<td><p> {{ hardware|build_type }} </p> </td>
</tr>

<tr align="center">

<td >
Service Tab
</td>
<td><p> {{ hardware.service_tab }} </p> </td>
</tr>
<tr align="center">

<td >
Serial Number
</td>
<td><p> {{ hardware.serial_number }} </p> </td>
</tr>

<tr align="center">

<td >
CPU Type
</td>
<td><p> {{ hardware.cpu_type}} </p> </td>
</tr>

<tr align="center">

<td >
cores
</td>
<td><p> {{hardware.cores}} </p> </td>
</tr>

<tr align="center">
<td >
RAM(GB)
</td>
<td><p> {{ hardware.ramGB}} </p> </td>
</tr>
</form>
</table>

{% endif %}
{% endblock %}
--
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+***@googlegroups.com.
To post to this group, send email to django-***@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/b8183578-a7c0-4b0a-a174-6ea7a5a470b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Matthew Pava
2018-11-27 15:02:23 UTC
Permalink
Override the __str__ method.
https://docs.djangoproject.com/en/2.1/ref/models/instances/#str


From: django-***@googlegroups.com [mailto:django-***@googlegroups.com] On Behalf Of Mike Sacauskis
Sent: Monday, November 26, 2018 5:36 PM
To: Django users
Subject: Human Readable Values


[Screenshot.png]
Hi

I'm new to DJango and have a question about how to display some model data in a human readable form. I have three fields, one is an IP Address <django.db.models.fields.IPAddressField> and two are <django.db.models.fields.IntegerField>. When I render the template I get the class name but no values. How do I render the values?

Thanks

Mike
--
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+***@googlegroups.com<mailto:django-users+***@googlegroups.com>.
To post to this group, send email to django-***@googlegroups.com<mailto:django-***@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/e3067097-f156-43a9-9821-abda50b08b72%40googlegroups.com<https://groups.google.com/d/msgid/django-users/e3067097-f156-43a9-9821-abda50b08b72%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+***@googlegroups.com.
To post to this group, send email to django-***@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/2af8a2d80d574969b615aae746216c30%40iss2.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...