Changes between Version 1 and Version 2 of Ticket #31282
- Timestamp:
- Feb 17, 2020, 2:51:40 PM (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #31282 – Description
v1 v2 1 It seems that I can no longer pass a list of pks to RelatedManager.set(..). 2 Alternatively, passing a list of objects works as expected. 1 3 {{{ 2 >>> i = ProductImage.objects.get(pk=100) 3 >>> p.images.set([100]) 4 >>> p = Product.objects.all()[0] 5 >>> p 6 <Product: <Product pk=587 barcode=041390007019>> 7 >>> p.images.set([1]) 4 8 Traceback (most recent call last): 5 9 File "<console>", line 1, in <module> … … 10 14 File "/usr/local/lib/python3.8/dist-packages/django/db/models/fields/related_descriptors.py", line 648, in check_and_update_obj 11 15 raise TypeError("'%s' instance expected, got %r" % ( 12 TypeError: 'ProductImage' instance expected, got 1 0016 TypeError: 'ProductImage' instance expected, got 1 13 17 18 class Product(m.Model): 19 ... 20 21 class ProductImage(m.Model): 22 product = m.ForeignKey( 23 Product, 24 on_delete=m.CASCADE, 25 related_name='images', 26 ) 27 }}}