Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Django Class-based Views Customizing Class-based Views Custom Mixin

Mixins task 4/4 - Task 1 no longer passing

I've gone through the task a few times with different approaches, and cant seem to see what I'm doing wrong. Each individual step seems right. (and tasks 1 to 3 all pass on their own). What am I missing?

from django.contrib.auth.mixins import LoginRequiredMixin, SuccessMessageMixin
from django.core.urlresolvers import reverse_lazy
from django.views import generic

from . import mixins
from . import models

class ArticleList(generic.ListView):
    model = models.Article

class ArticleDetail(generic.DeleteView, generic.DetailView):
    model = models.Article
    template_name = 'articles/article_detail.html'

class ArticleCreate(LoginRequiredMixin, SuccessMessageMixin, generic.CreateView):
    fields = ('title', 'body', 'author', 'published')
    model = models.Article
    success_message = "Article Created!"

class ArticleUpdate(LoginRequiredMixin, SuccessMessageMixin, generic.UpdateView):
    fields = ('title', 'body', 'author', 'published')
    model = models.Article

    def get_success_message(self):
        obj = self.get_object()
        return "{} updated!".format(obj.title)

class ArticleDelete(LoginRequiredMixin, generic.DeleteView):
    model = models.Article
    success_url = reverse_lazy('articles:list')

class ArticleSearch(generic.ListView):
    model = models.Article

    def get_queryset(self):
        qs = super().get_queryset()
        term = self.kwargs.get('term')
        if term:
            return qs.filter(body__icontains=term)
        return qs.none()
from django.contrib import messages

class SuccessMessageMixin:
    success_message = ""

    def get_success_message(self):
        return self.success_message

    def form_valid(self,form):
        formmessage = self.get_success_message()
        return super().form_valid(form)  

1 Answer

I re-typed everything, and it passed with no changes. Must have been some hidden characters in "cut-'n-paste"