Created
January 2, 2013 01:30
-
-
Save anonymous/4431497 to your computer and use it in GitHub Desktop.
a modelform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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