Skip to content

Instantly share code, notes, and snippets.

@AeroNotix
Created March 28, 2012 18:59
Show Gist options
  • Select an option

  • Save AeroNotix/2229463 to your computer and use it in GitHub Desktop.

Select an option

Save AeroNotix/2229463 to your computer and use it in GitHub Desktop.
from django.db import models
class Tbluser(models.Model):
"""
Models the user table and provides the admin interface with the
niceties it needs.
"""
USER_TYPE = (
('ADMIN', 'Administrator'),
('RUSER', 'Regular User')
)
MARKET_CHOICES = (
('BG', 'Germany'),
('BK', 'Kirchberg'),
('CZ', 'Czech')
)
PROCESS_CHOICES = (
('AP', 'Accounts Payable'),
('AR', 'Accounts Receivable'),
('AO', 'Accounting Operations')
)
user_id = models.EmailField(max_length=105,
verbose_name=("UserID / HP Email"))
firstname = models.CharField(max_length=60,
db_column='uFirstName',
verbose_name=("First Name"))
lastname = models.CharField(max_length=60,
db_column='uLastName',
verbose_name=("Last Name"))
password = models.CharField(max_length=60,
db_column='uPassword')
user_type = models.CharField(max_length=5,
choices=USER_TYPE)
market = models.CharField(max_length=2,
db_column='uMarket',
choices=MARKET_CHOICES)
process = models.CharField(max_length=2,
db_column='uProcess',
choices=PROCESS_CHOICES)
start_date = models.DateField(db_column='Start_Date',
verbose_name=("Start Date"))
breaklength = models.TimeField(db_column='breakLength',
verbose_name=("Break Length"))
shiftlength = models.TimeField(db_column='shiftLength',
verbose_name=("Shift Length"))
def display_user_type(self):
return self.user_type
def __unicode__(self):
"""
How the row is represented in admin
"""
return ' - '.join([ self.user_id,
' '.join([self.firstname, self.lastname])
]
)
class Meta:
db_table = u'tbluser'
class Tblauthorization(models.Model):
"""
Links Administrators (managers) with their team.
"""
admin = models.ForeignKey(Tbluser,
limit_choices_to = {
'user_type':'ADMIN'
},
related_name="admin_foreign"
)
users = models.ManyToManyField(Tbluser,
limit_choices_to = {
'user_type':'RUSER'
},
related_name="subordinates",
verbose_name = ("Additional Users")
)
def display_users(self):
table_header = """
<table>
<tr>
<th>Name</th>
</tr>
"""
table_data_string = """
<tr>
<td>{0} {1}</td>
</tr>
"""
table_inner_list = [table_data_string.format(user.firstname,
user.lastname
)
for user in self.users.all()
]
return ''.join([
table_header,
''.join([table_entry for table_entry in table_inner_list]),
'\n</table>'
]
)
display_users.allow_tags = True
display_users.short_discription = "Subordinate Users"
def __unicode__(self):
return str(self.admin)
class Meta:
db_table = u'tblauthorization'
class TrackingEntry(models.Model):
"""
Used to create an entry into the database showing working time on a particular day.
TODO: Add choices for daytype, i.e., workday/sickday/holiday
"""
user = models.ForeignKey(Tbluser, related_name="user_tracking")
start_time = models.TimeField(blank=False)
end_time = models.TimeField(blank=False)
breaks = models.TimeField(blank=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment