Skip to content

Instantly share code, notes, and snippets.

@thebookworm101
Forked from anonymous/modelform
Created January 2, 2013 01:31
Show Gist options
  • Save thebookworm101/4431499 to your computer and use it in GitHub Desktop.
Save thebookworm101/4431499 to your computer and use it in GitHub Desktop.
class TimeLogForm(forms.ModelForm):
class Meta:
exclude = ['begin_sec']
model = TimeLog
def __init__(self, *args, **kw):
super(TimeLogForm).__init__(self, *args, **kw)
def save(self, *args, **kw):
instance = super(TimeLogForm, self).save(commit=False)
last_entry = TimeLog.objects.all().order_by('-id')[0] #filter by id here
if last_entry:
instance.begin_sec = last_entry.begin_sec
else:
# this is the very first record do something
pass
instance.save()
return instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment