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 Forms More on Models Abstract Model

Great! Now make a new model, Review, that inherits from Article. It should have one new field, rating, which is an Integ

Wondering how I should go about this task. Task 2...

articles/models.py
from django.db import models


class Article(models.Model):
    headline = models.CharField(max_length=255)
    publish_date = models.DateTimeField()
    content = models.TextField()
    writer = models.ForeignKey('Writer')
    class Meta:
        abstract = True

    def __str__(self):
        return self.headline


class Writer(models.Model):
    name = models.CharField(max_length=255)
    email = models.EmailField()
    bio = models.TextField()

    def __str__(self):
        return self.name

    def mailto(self):
        return '{} <{}>'.format(self.name, self.email)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Here are the steps broken down:

  • Now make a new model, Review, ...

use class to declare the model

  • ...that inherits from Article.

use Article as the parent class

  • It should have one new field, rating, which is an IntegerField with a default value of 5.

this has the same format as the other fields, but with parameter default set to 5

Post back if you need more help. Good luck!!!

class Review: rating=5 ?

I feel like this is too simple. Not sure why it's not clicking in my head...

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

β€œone new field, rating, which is an IntegerField with a default value of 5”

class Review: rating = models.IntegerField(default=5)

I'm not getting it

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Last piece:

use class to declare the model Review . ...that inherits from Article.

I have it under Article similar to my class Meta

thank you finally worked