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 trialChris Couch
Front End Web Development Techdegree Graduate 25,326 PointsGreat! 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...
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
Treehouse Moderator 68,441 PointsHere 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!!!
Chris Couch
Front End Web Development Techdegree Graduate 25,326 PointsChris Couch
Front End Web Development Techdegree Graduate 25,326 Pointsclass Review: rating=5 ?
I feel like this is too simple. Not sure why it's not clicking in my head...
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 Pointsβone new field,
rating
, which is an IntegerField with a default value of 5βChris Couch
Front End Web Development Techdegree Graduate 25,326 PointsChris Couch
Front End Web Development Techdegree Graduate 25,326 Pointsclass Review: rating = models.IntegerField(default=5)
I'm not getting it
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsLast piece:
Chris Couch
Front End Web Development Techdegree Graduate 25,326 PointsChris Couch
Front End Web Development Techdegree Graduate 25,326 PointsI have it under Article similar to my class Meta
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 Pointsclass Review(Article):
Chris Couch
Front End Web Development Techdegree Graduate 25,326 PointsChris Couch
Front End Web Development Techdegree Graduate 25,326 Pointsthank you finally worked