Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Class-based Views Customizing Class-based Views Franken-Views

no form field is coming Please Help me in solving I'm using Django 1.10

no form field is coming, I'm combining two generic classes in a single view,

code of View class TeamDetailView(DetailView, UpdateView): fields = ("name", "practice_location", "coach") model = models.Team template_name = "teams/team_detail.html"

5 Answers

Bryson Gilreath
Bryson Gilreath
5,947 Points

I had this same problem and it seems to have been fixed by putting the fields assignment after the model assignment. So the view looks like this:

class TeamDetailView(DetailView, UpdateView):
    model = models.Team
    fields = ("name", "practice_location", "coach")
    template_name = "teams/team_detail.html"
Vitaly Myshlaev
Vitaly Myshlaev
5,883 Points

I have the same problem. After digging into StackOverFlow it looks like a bad idea to mix CBV

if the coach team is same the user login on the admin. The fields will show up, because we added the form in the if block.

Erika Suzuki
Erika Suzuki
20,299 Points

When in doubt, just use FBV.

Jorge Pereira
Jorge Pereira
1,469 Points

In this challenge ...

"I want to be able to search for articles with a certain term in their body. In the ArticleSearch view, override the get_queryset method and return any Articles where the body contains self.kwargs["term"]. Make sure it's a case-insensitive search. Oh, and the term could be blank, so handle that case, too, and return zero records."

My answer:

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

def get_queryset(self):
    if not self.kwargs["term"]:
        return self.model.objects.none()
    else
        return self.model.objects.filter(body__icontains=self.kwargs["term"])

I can not get through the task. What is wrong with my code?