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

Simon Amz
Simon Amz
4,606 Points

Can't create review as bulk

Hi there,

I cannot succeed to create some data in bulk but when I test it in the shell it works perfectly.

Here is attached my code.

Thanks for your response

products/emergency.py
from . import models

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

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

You are really close. Two fixes needed:

  • Since the import was for models, the Review objects need to be referred to as models.Review
  • The parameter should be product_id instead of product

Post back if you have more questions. Good luck!!

Simon Amz
Simon Amz
4,606 Points

Hi Chris got it, thanks.

Now, what is the difference between:

  • product_id
  • product.id
  • product_pk
  • product.pk

thanks for the explanation, it's not very clear on the video.