Commit 0ebd4e9b authored by Dexter Sapugay's avatar Dexter Sapugay

updated models and database in django

parent b8c19b84
from django.contrib import admin from django.contrib import admin
from .models import Employee, Productivity, JobOrder, Position, History, Dashboard
admin.site.register(Employee)
admin.site.register(Productivity)
admin.site.register(JobOrder)
admin.site.register(Position)
admin.site.register(History)
admin.site.register(Dashboard)
# Generated by Django 4.0.4 on 2023-02-13 16:35
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Employee',
fields=[
('employee_id', models.CharField(max_length=10, primary_key=True, serialize=False)),
('employee_fname', models.CharField(max_length=255)),
('employee_mname', models.CharField(blank=True, max_length=255, null=True)),
('employee_lname', models.CharField(max_length=255)),
('employee_sex', models.CharField(max_length=1)),
('employee_bday', models.DateField()),
('employee_email', models.CharField(max_length=255)),
('employee_num', models.CharField(blank=True, max_length=10, null=True)),
('employee_emergnum', models.CharField(blank=True, max_length=10, null=True)),
],
),
migrations.CreateModel(
name='Position',
fields=[
('position_id', models.CharField(max_length=10, primary_key=True, serialize=False)),
('history_no', models.CharField(max_length=10)),
('position_name', models.CharField(max_length=255)),
],
),
migrations.CreateModel(
name='Productivity',
fields=[
('report_no', models.CharField(max_length=10, primary_key=True, serialize=False)),
('prod_date', models.DateField()),
('workinghours', models.DurationField()),
('remarks', models.TextField(blank=True, max_length=2000)),
('prod_score', models.FloatField(null=True)),
('employee', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='EmployeeProdDB.employee')),
],
),
migrations.CreateModel(
name='JobOrder',
fields=[
('joborder_no', models.CharField(max_length=10, primary_key=True, serialize=False)),
('process', models.CharField(max_length=255)),
('status', models.CharField(max_length=255)),
('report_no', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='EmployeeProdDB.productivity')),
],
),
migrations.CreateModel(
name='History',
fields=[
('history_no', models.CharField(max_length=10, primary_key=True, serialize=False)),
('employee_fname', models.CharField(max_length=255)),
('employee_mname', models.CharField(blank=True, max_length=255)),
('employee_lname', models.CharField(max_length=255)),
('position_name', models.CharField(max_length=255)),
('position_startdate', models.DateField()),
('position_enddate', models.DateField(null=True)),
('employee', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='EmployeeProdDB.employee')),
('position', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='EmployeeProdDB.position')),
],
),
migrations.CreateModel(
name='Dashboard',
fields=[
('dashboard_id', models.CharField(max_length=10, primary_key=True, serialize=False)),
('report_no', models.CharField(max_length=255)),
('timespan', models.DurationField()),
('displaytype', models.CharField(max_length=255)),
('total_workinghours', models.DurationField()),
('contribution', models.CharField(max_length=10)),
('avgprodscore', models.FloatField()),
('employee', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='EmployeeProdDB.employee')),
],
),
]
from django.db import models from django.db import models
#from .employee import Employee
class Upload(models.Model): class Upload(models.Model):
file = models.FileField(upload_to='Uploaded CSV/') file = models.FileField(upload_to='Uploaded CSV/')
class Meta: class Meta:
app_label = 'your_app_name' app_label = 'your_app_name'
class Employee(models.Model):
employee_id = models.CharField(max_length=10, primary_key=True)
employee_fname = models.CharField(max_length=255)
employee_mname = models.CharField(max_length=255, blank=True, null=True)
employee_lname = models.CharField(max_length=255)
employee_sex = models.CharField(max_length=1)
employee_bday = models.DateField()
employee_email = models.CharField(max_length=255)
employee_num = models.CharField(max_length=10, blank=True, null=True)
employee_emergnum = models.CharField(max_length=10, blank=True, null=True)
# class Meta:
# db_table = 'employee'
class Productivity(models.Model):
report_no = models.CharField(max_length=10, primary_key=True)
employee = models.ForeignKey('Employee', on_delete=models.CASCADE)
prod_date = models.DateField()
workinghours = models.DurationField()
remarks = models.TextField(max_length=2000, blank=True)
prod_score = models.FloatField(null=True)
# class Meta:
# constraints = [
# models.ForeignKeyConstraint(
# ['employee_id'],
# ['employee.employee_id'],
# name='productivity_fk'
# )
# ]
class JobOrder(models.Model):
joborder_no = models.CharField(max_length=10, primary_key=True)
report_no = models.ForeignKey('Productivity', on_delete=models.CASCADE)
process = models.CharField(max_length=255)
status = models.CharField(max_length=255)
class Position(models.Model):
position_id = models.CharField(max_length=10, primary_key=True)
history_no = models.CharField(max_length=10)
position_name = models.CharField(max_length=255)
# class Meta:
# constraints = [
# models.ForeignKeyConstraint(
# ['history_no'],
# ['history.history_no'],
# name='position_fk'
# )
# ]
class History(models.Model):
history_no = models.CharField(max_length=10, primary_key=True)
employee = models.ForeignKey('Employee', on_delete=models.CASCADE)
position = models.ForeignKey('Position', on_delete=models.CASCADE)
employee_fname = models.CharField(max_length=255)
employee_mname = models.CharField(max_length=255, blank=True)
employee_lname = models.CharField(max_length=255)
position_name = models.CharField(max_length=255)
position_startdate = models.DateField()
position_enddate = models.DateField(null=True)
# class Meta:
# constraints = [
# models.ForeignKeyConstraint(
# ['employee_id'],
# ['employee.employee_id'],
# name='history_fk1'
# ),
# models.ForeignKeyConstraint(
# ['position_id'],
# ['position.position_id'],
# name='history_fk2'
# )
# ]
class Dashboard(models.Model):
dashboard_id = models.CharField(max_length=10, primary_key=True)
employee = models.ForeignKey('Employee', on_delete=models.CASCADE)
report_no = models.CharField(max_length=255)
timespan = models.DurationField()
displaytype = models.CharField(max_length=255)
total_workinghours = models.DurationField()
contribution = models.CharField(max_length=10)
avgprodscore = models.FloatField()
# class Meta:
# constraints = [
# models.ForeignKeyConstraint(
# ['employee_id'],
# ['employee.employee_id'],
# name='dashboard_fk1'
# ),
# models.ForeignKeyConstraint(
# ['report_no'],
# ['productivity.report_no'],
# name='dashboard_fk2'
# )
# ]
\ No newline at end of file
from django.shortcuts import render, redirect import csv
from .models import Upload from datetime import datetime
from django.shortcuts import render
from .models import Productivity
from django.shortcuts import render from django.shortcuts import render
...@@ -7,6 +9,17 @@ from django.shortcuts import render ...@@ -7,6 +9,17 @@ from django.shortcuts import render
def home(request): def home(request):
return render(request, 'EmployeeProdDB/index.html') return render(request, 'EmployeeProdDB/index.html')
def csv_import(request):
with open('C:\Users\dxsap\Downloads\IPS_dummy_data.csv') as f:
reader = csv.reader(f)
for row in reader:
my_model = Productivity(
field1=row[0],
field2=row[1],
field3=datetime.strptime(row[2], '%Y-%m-%d').date()
)
my_model.save()
return render(request, 'csv_imported.html')
#def handle_file_upload(request): #def handle_file_upload(request):
# if request.method == 'POST': # if request.method == 'POST':
# file = request.FILES.get('file-input') # file = request.FILES.get('file-input')
......
# 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 and OneToOneField 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 django.db import models
# Unable to inspect table 'employee'
# The error was: cannot unpack non-iterable NoneType object
...@@ -79,6 +79,10 @@ DATABASES = { ...@@ -79,6 +79,10 @@ DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '3306',
} }
} }
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment