1👍
✅
Your code for creating a new Product
is correct. After creating a Responde
object, you can set it as the foreign key for your product.
# create a Responde object
r = Responde.objects.create()
for xmldata in products_xml:
p = Product(
name=xmldata['ProductName'],
description=xmldata['ProductDescription'],
price=xmlData['ProductPrice'],
)
# add product to responde "r"
p.responde = r
p.save()
# this queryset contains all the products added above
r.product_set.all()
Source:stackexchange.com