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 ORM Basic ORM Usage Bulk create

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.

Thanks,

products/emergency.py
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)
    ])

2 Answers

Instead of product use product_id

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,716 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)
    ])