Skip to content

Instantly share code, notes, and snippets.

@thebookworm101
Created January 2, 2013 15:22
Show Gist options
  • Save thebookworm101/4435319 to your computer and use it in GitHub Desktop.
Save thebookworm101/4435319 to your computer and use it in GitHub Desktop.
django url
## how would i make this url more robust?
url(r'^$',
'job.list_detail.object_list',
{
'queryset': Job.objects.all(), ## how do i make this robust? right now if the database is empty i get an error
},
name='job_slug_index'),
##here is the error:
DatabaseError at /timelog/
(1054, "Unknown column 'timelog_timelog.' in 'field list'")
Request Method: GET
Request URL: http://localhost:8000/timelog/
Django Version: 1.4.3
Exception Type: DatabaseError
Exception Value:
(1054, "Unknown column 'timelog_timelog.client' in 'field list'")
### here is the model
class Log(models.Model):
"""Represents a time logger system"""
begin_sec = models.DateTimeField( auto_now_add=False,)
end_sec= models.DateTimeField( auto_now_add=False,)
job = models.CharField(max_length=255)
assigner = models.CharField(max_length=100)
client= models.IntegerField(choices=MY_CATEGORIES)
name = models.IntegerField(choices=MY_SUBCATEGORIES)
## and the model form:
class LogForm(forms.ModelForm):
""" this handles the start_time and end_time defaults"""
class Meta:
exclude = ['slug','begin_sec']
model = Job
def __init__(self, *args, **kw):
super(LogForm).__init__(self, *args, **kw)
def save(self,user, *args, **kw):
instance = super(JobForm, self).save(commit=False)
last_entry = Job.objects.aggregate(max_end_sec=models.Max('end_sec'))['max_end_time']
if last_entry:
instance.begin_sec = last_entry.end_sec
else:
#if this is the very first record pass
pass
instance.save()
return instance
##here are my choices:
MY_CATEGORIES = (
('1', 'two'),
('2', 'one'),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment