0

I'm quite stumped on this one. I'm working with a Task Tracking system and after adding or updating task objects they are not being refreshed on the client-facing website, but in the admin site they are there.

The problem resides in my TaskCreateView, but I can't figure out why. I know this because I've created a simple test TaskListView and it displays the updated values. I need the TaskCreateView to both display task objects as well as create a new task object.

Here is my code, hopefully someone has an idea, because I've ran out.

#urls.py
urlpatterns = patterns('',
    url(r'^$',  TaskCreateView.as_view(), name='task-create'),
    ...
)

#views.py
class TaskCreateView(MultipleObjectMixin, CreateView):
    '''
    base create view for tasks
    '''
    model = Task
    form_class = TaskCreateForm
    template_name = "flowtask/content/tasks.html"
    object_list = Task.objects.all()
    success_url = reverse_lazy('task-create')
    load_modal = "createTaskModal"

    def form_invalid(self, form, **kwargs):
        #need to add in the error status and modal to the context_data
        context = self.get_context_data(**kwargs)
        context['status'] = 'error'
        context['load_modal'] = self.load_modal
        context['form'] = form
        # return super(TaskCreateView, self).form_invalid(form)
        return self.render_to_response(context)

    def get_context_data(self, **kwargs):
        context = super(TaskCreateView, self).get_context_data(**kwargs)
        context['create_form'] = self.get_form(self.form_class)
        return context

I am using Django 1.6 and python 3.3.

2
  • Presumably the relevant data is in object_list. How are you passing that to the template? Commented Mar 5, 2014 at 9:33
  • I created a simple test template that just had something like {% for o in object_list %}{{ o }}{% endfor %} and it didn't show the updates with this view, but with a generic ListView it shows the updates/additions Commented Mar 5, 2014 at 14:40

2 Answers 2

1

Remove the object_list from your class definition and move it to your get_context_data method:

def get_context_data(self, **kwargs):
    context = super(TaskCreateView, self).get_context_data(**kwargs)
    context['create_form'] = self.get_form(self.form_class)
    context['object_list'] = Task.objects.all()
    return context
Sign up to request clarification or add additional context in comments.

Comments

0

You shouldn't be defining object_list at the class level, but queryset or model.

1 Comment

When I do that the super(TaskCreateView, self).get_context_data(**kwargs) fails. In the super it's hitting ListView and failing on: queryset = kwargs.pop('object_list', self.object_list) Maybe I'm getting the context data incorrectly?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.