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

Django ORM bulk_create challenge

I am not getting what I am doing wrong here:

the task is to bulk create ratings for the product with id 1 with ratings 2,3 and 5

products/emergency.py
from . import models

def fix_25():
    models.Review.objects.bulk_create([Review(product_id=1,rating=2),
                                       Review(product_id=1,rating=3),
                                       Review(product_id=1,rating=5)])

2 Answers

Alx Ki
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alx Ki
Python Web Development Techdegree Graduate 14,822 Points

Hi, Sabine Maennel !

You have models imported, so to make python know where Review model is, you use models.Review every time.

You may also "from .models import Review".

Thank you so much Alexey, I was kind of blind for this this morning when I did the challenge, but now, thanks to you I could make it pass.

from . import models

def fix_25():
    models.Review.objects.bulk_create([
        models.Review(product_id=1,rating=2),
        models.Review(product_id=1,rating=3),
        models.Review(product_id=1,rating=5)
    ])