mirror of https://github.com/snachodog/mybuddy.git
Assign user field during Timer instance save.
This commit is contained in:
parent
1b015d4dde
commit
ac2cc8ec5f
|
@ -75,6 +75,16 @@ class TimerForm(forms.ModelForm):
|
|||
model = Timer
|
||||
fields = ['name']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.user = kwargs.pop('user')
|
||||
super(TimerForm, self).__init__(*args, **kwargs)
|
||||
|
||||
def save(self, commit=True):
|
||||
instance = super(TimerForm, self).save(commit=False)
|
||||
instance.user = self.user
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
|
||||
class TummyTimeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
|
|
|
@ -147,6 +147,11 @@ class TimerAdd(PermissionRequiredMixin, CreateView):
|
|||
permission_required = ('core.add_timer',)
|
||||
form_class = TimerForm
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(TimerAdd, self).get_form_kwargs()
|
||||
kwargs.update({'user': self.request.user})
|
||||
return kwargs
|
||||
|
||||
def get_success_url(self):
|
||||
if resolve(self.request.POST['success_url']).url_name:
|
||||
url = self.request.POST['success_url']
|
||||
|
|
Loading…
Reference in New Issue