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 Customizing the Django Admin Customizing the Detail View You're an Admin Boss!

Haydar Al-Rikabi
Haydar Al-Rikabi
5,971 Points

Saving a list view does not update its attributes correctly.

Updating a list view within the admin site works through the bulk actions menu. Both 'status' and 'is_live' fields are updated correctly when I click on the 'Go' button next to the actions menu.

However, when I edit the status of a course through the status menu and hit 'Save', I notice that only the 'status' field is updated but not the 'is_live' field.

What shall I add to the workspace code of that lesson in order to make it work.


2 Answers

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

If you want to add the functionality where a status change to "Published" automatically causes setting is_live=True, you can add this to the Course model:

class Course(models.Model):
    # ...

    # Overwrite the save method to add custom action
    def save(self, *args, **kwargs):
        if self.status == 'p':
            # if status is "Published", force is_live to True
            self.is_live = True
        # call parent save method to complete the save action
        super().save(*args, **kwargs)