-
-
Save orf/229818a25c59bd06a52a8e97dd66bc7a to your computer and use it in GitHub Desktop.
trying to get {{ t.start_stamp }} to display as a date, its saved as a Unix EPOC timestamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is an auto-generated Django model module. | |
# You'll have to do the following manually to clean this up: | |
# * Rearrange models' order | |
# * Make sure each model has one field with primary_key=True | |
# * Make sure each ForeignKey has `on_delete` set to the desired behavior. | |
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table | |
# Feel free to rename the models, but don't rename db_table values or field names. | |
from __future__ import unicode_literals | |
from django.db import models | |
from datetime import datetime | |
class BtBoard(models.Model): | |
serial = models.CharField(max_length=32) | |
reference = models.CharField(max_length=12) | |
ref_num = models.CharField(max_length=12) | |
product = models.CharField(db_column='Product', max_length=32) # Field name made lowercase. | |
location = models.IntegerField() | |
status = models.CharField(max_length=32) | |
kit_id = models.IntegerField() | |
salesorderno = models.CharField(db_column='SalesOrderNo', max_length=32) # Field name made lowercase. | |
locked = models.IntegerField() | |
productionentrynumber = models.CharField(db_column='ProductionEntryNumber', max_length=32) # Field name made lowercase. | |
production_stamp = models.IntegerField() | |
notes = models.CharField(max_length=255) | |
@property | |
def production_stamp_datetime(self): | |
return datetime.fromtimestamp(self.production_stamp) | |
class Meta: | |
managed = False | |
db_table = 'bt_board' | |
class BtTransaction(models.Model): | |
start_stamp = models.IntegerField() | |
userid = models.IntegerField() | |
test_type = models.CharField(max_length=12) | |
reference = models.CharField(max_length=32) | |
ref_num = models.IntegerField() | |
test_slot = models.IntegerField() | |
test_sw = models.CharField(max_length=32) | |
test_func = models.IntegerField() | |
test_run = models.CharField(max_length=12) | |
status = models.CharField(max_length=12) | |
resol_id = models.IntegerField() | |
rma_id = models.IntegerField() | |
notes = models.CharField(max_length=256) | |
board = models.ForeignKey(BtBoard, on_delete=models.CASCADE) | |
@property | |
def start_stamp_datetime(self): | |
return datetime.fromtimestamp(self.start_stamp) | |
class Meta: | |
managed = False | |
db_table = 'bt_transaction' | |
class Location(models.Model): | |
name = models.TextField() | |
class Meta: | |
managed = False | |
db_table = 'location' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'layouts/base.html' %} | |
{% block title %} | |
- Report | |
{% endblock %} | |
{% block content %} | |
{% if trans_list %} | |
<table class="table table-striped table-hover"> | |
<thead> | |
<tr> | |
<th>Start Stamp</th> | |
<th>User ID</th> | |
<th>Board ID</th> | |
<th>Reference</th> | |
<th>Ref Num</th> | |
<th>Test</th> | |
</tr> | |
</thead> | |
<tbody> | |
{% for t in trans_list %} | |
<tr> | |
<td>{{ t.start_stamp|date }}</td> | |
<td>{{ t.userid }}</td> | |
<td>{{ t.board.id }}</td> | |
<td>{{ t.reference }}</td> | |
<td>{{ t.ref_num }}</td> | |
<td>{{ t.test }}</td> | |
</tr> | |
{% endfor %} | |
</tbody> | |
</table> | |
{% else %} | |
<p>No transactions!</p> | |
{% endif %} | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from django.http import HttpResponse | |
import time | |
import datetime | |
from .models import BtBoard, BtTransaction | |
def index(request): | |
return render(request, 'boardtracker/index.html') | |
def report(request): | |
startdate = time.mktime(datetime.datetime.strptime(request.POST['startdate'], "%Y-%m-%d").timetuple()) | |
enddate = time.mktime(datetime.datetime.strptime(request.POST['enddate'], "%Y-%m-%d").timetuple()) | |
refnum = request.POST['ref_num'] | |
if refnum == '': | |
transactions = BtTransaction.objects.filter(start_stamp__gte=startdate, start_stamp__lte=enddate).order_by('-board') | |
else: | |
transactions = BtTransaction.objects.filter(start_stamp__gte=startdate, start_stamp__lte=enddate, ref_num=refnum).order_by('-board') | |
context = { | |
'trans_list': transactions, | |
} | |
return render(request, 'boardtracker/report.html', context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment