views.py
@render_to('')
def tasks_add(request, template="tasks/add.html"):
if request.method == 'POST':
form = TaskForm(request.POST)
if form.is_valid():
task = form.save(request.user)
return HttpResponseRedirect('/tasks/details/%s' % task.id)
else:
form = TaskForm()
return {'form': form,}, template
forms.py
class TaskForm(ModelForm):
class Meta:
model = Task
fields = ('name', 'description', 'price',)
def save(self, user=None, commit=True):
task = super(TaskForm, self).save(commit=False)
task.buyer = user
if commit:
task.save()
return task
Немає коментарів:
Дописати коментар