|
Posted by ramesh03 |
|
|
Hi,
Normally, for name i am calling like {{ emplist.name }}.for dept calling like {{ emplist.dept }}. Here 'name' and 'dept' are column names in my database table.If my column name is 2012-02-16 Then suppose to call like {{ emplist.2012-02-16 }}.But i know this is not the right way. So how to call with date as column name ? Thanks. |
|
|
Posted by arwa |
|
|
In your model if you don't want to have this 2012-02-16 for field name you can use db_column.
https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.Field.db_column Ex. class MyModel(models.Model): mydate = models.YourTypeField(db_column='2012-02-16') In this way you can use this for template {{yourdata.mydate}} One question: You are sure that you want 2012-02-16 for a db column name |
|
|
Posted by ramesh03 |
|
|
Thanks for your reply.
Actually i am working on database now.But i don't know any thing about database.What i want exactly is... I have multiple projects(2 or more) with multiple users( around 20), So Daily they should enter what they did every day. Here, first they have to select project and what percentage(%) they did, and write some description about work.This should happen everyday. Because of this,Every day i am planing to save data with date wise(date as column name). My database table is something like this... emp_id ----- emp_name ------ 2012-02-15 --------------- 2012-02-16 --------------- 2012-02-17 1001 ----- - somename ----- proj1,2.5%,polishing --- proj2,0.5%,testing --------- proj1,1.0%,wire remooval 1003 ------ somename ------ proj3,0.5%,test ---------- proj1,3.5%,polish ---------- -- proj1,3.5%,polish I am planing to do like this.If you have any suggestion, please let me know. And one more thing here i am using"south" for creating column daily. add_column('mySite_currentprojects',int(currDate), models.CharField(max_length = 10,null=True)) This is from view.py not from model.py --- Last Edited by ramesh03 at 2012-02-17 01:22:54 --- |
|
|
Posted by arwa |
|
|
I don't think that I understood very well but the idea is really ok.
Some months ago I start something like this to create a product like TRAC (is this your purpose ?). I try to give you some ideas on it. Put one column for one day is not a good idea. Is better to have a model with date and, a field with text, and a FK to user (and percentage if you want). This is an example about model relations (you can put percent in task also):
class Task(models.Model):
project = models.ForeignKey('Project')
activity = models.ForeignKey('Activity')
date = models.DateField()
time_from = models.TimeField(blank=True,null=True,help_text='If sets, this overload delta values')
time_to = models.TimeField(blank=True,null=True,help_text='If sets, this overload delta values')
time_delta_mins = models.IntegerField(blank=True,null=True)
time_delta_hours = models.IntegerField(blank=True,null=True)
note = models.TextField(blank=True)
billable = models.BooleanField(blank=True)
user = models.ForeignKey('auth.User')
class Meta:
verbose_name = _(u'Task')
verbose_name_plural = _(u'Tasks')
db_table = 'data_tasks'
def __unicode__(self):
return '%s - %s' %(self.date,self.user)
def time_delta(self):
return '%s:%s' % (self.time_delta_hours,self.time_delta_mins)
class Project(models.Model):
name = models.CharField(max_length=255)
customer = models.ForeignKey('Customer',blank=True,null=True)
users = models.ManyToManyField('auth.User',blank=True,null=True)
class Meta:
verbose_name = _(u'Project')
verbose_name_plural = _(u'Projects')
db_table = 'data_projects'
def __unicode__(self):
return '%s' %(self.name)
class Customer(models.Model):
name = models.CharField(max_length=255)
piva = models.CharField(max_length=31,blank=True,null=True)
cf = models.CharField(max_length=31,blank=True,null=True)
phone = models.CharField(max_length=31,blank=True,null=True)
cell = models.CharField(max_length=31,blank=True,null=True)
fax = models.CharField(max_length=31,blank=True,null=True)
email = models.EmailField(max_length=255,blank=True,null=True)
class Meta:
verbose_name = _(u'Customer')
verbose_name_plural = _(u'Customers')
db_table = 'data_customers'
def __unicode__(self):
return '%s' %(self.name)
class Activity(MPTTModel):
name = models.CharField(max_length=255)
description = models.TextField(blank=True,null=True)
# mptt system
level = models.IntegerField(_('Level'),editable=False)
parent = models.ForeignKey("self",blank=True,null=True, related_name='children',verbose_name=_('Parent'))
lft = models.IntegerField(_(u'Left'))
rght = models.IntegerField(_(u'Right'))
tree_id = models.IntegerField(_(Tree ID'))
projects = models.ManyToManyField('Project',blank=True,null=True)
class Meta:
verbose_name = _(u'Activity')
verbose_name_plural = _(u'Activities')
db_table = 'data_activities'
def __unicode__(self):
return '%s' %(self.name)
|
|
|
Posted by ramesh03 |
|
|
Once again thanQ arwa.
|
|
|
Posted by arwa |
|
|
no problem
|


