class TaskForm(forms.ModelForm):
class Meta:
model = Task
fields = ('name', 'description', 'category')
def task_new(request):
if request.method == "POST":
form = TaskForm(request.POST)
if form.is_valid():
task = form.save(commit=False)
task.user = request.user
task.created = timezone.now()
task.save()
else:
form = TaskForm()
return render(request, 'post_new.html', locals())