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!
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
Steve Wehba831 Points
Code not passing for bulk_create
Could you please take a look at my code and let me know why it's not passing. The message I get is this:
You need to use
bulk_create to create the Review objects.; Make sure you create three Reviews.; Make sure you provide ratings of 2, 3, and 5.
Not tremendously helpful.
from . import models def fix_25(): models.Review.objects.bulk_create([ models.Review(product=1, rating=2), models.Review(product=1, rating=3), models.Review(product=1, rating=5) ])
KRIS NIKOLAISEN54,944 Points
Instead of product use product_id
Jeff MudayTreehouse Moderator 28,249 Points
You are really close!! All you need to do is to get the actual object as the argument rather than specifying the integer id.
from . import models def fix_25(): p = models.Product.objects.get(id=1) # add this line # make sure to set the product argument to the object p. models.Review.objects.bulk_create([ models.Review(product=p, rating=2), models.Review(product=p, rating=3), models.Review(product=p, rating=5) ])