Skip to content

Instantly share code, notes, and snippets.

Created January 2, 2013 01:30
Show Gist options
  • Save anonymous/4431497 to your computer and use it in GitHub Desktop.
Save anonymous/4431497 to your computer and use it in GitHub Desktop.
a modelform
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