Skip to content

Instantly share code, notes, and snippets.

@eclecticmiraclecat
Last active November 4, 2020 11:27
Show Gist options
  • Save eclecticmiraclecat/bd26ce63979b76ad8f982b437fd8a94b to your computer and use it in GitHub Desktop.
Save eclecticmiraclecat/bd26ce63979b76ad8f982b437fd8a94b to your computer and use it in GitHub Desktop.
# models.py
class Employee(models.Model):
  firstName = models.CharField(max_length=30)
  lastName = models.CharField(max_length=30)
  salary = models.FloatField()
  email = models.CharField(max_length=30)
Employee
+----+-----------+----------+--------+-------------------+
| id | firstName | lastName | salary |       email       |
+----+-----------+----------+--------+-------------------+
|  1 | bob       | hunter   |   2000 | [email protected]   |
|  2 | alice     | chain    |   3000 | [email protected] |
+----+-----------+----------+--------+-------------------+
# views.py
def display(request):
  employees = Employee.objects.all()
  return render(request, 'firstApp/index.html', {'employees': employees})
<!-- index.html -->
{% for employee in employees %}
  {{ employee.firstName}}
  {{ employee.salary }}
{% endfor %}

bob 2000.0 alice 3000.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment