Changes between Version 1 and Version 2 of Ticket #31282


Ignore:
Timestamp:
Feb 17, 2020, 2:51:40 PM (5 years ago)
Author:
Yu Li
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #31282 – Description

    v1 v2  
     1It seems that I can no longer pass a list of pks to RelatedManager.set(..).
     2Alternatively, passing a list of objects works as expected.
    13{{{
    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])
    48Traceback (most recent call last):
    59  File "<console>", line 1, in <module>
     
    1014  File "/usr/local/lib/python3.8/dist-packages/django/db/models/fields/related_descriptors.py", line 648, in check_and_update_obj
    1115    raise TypeError("'%s' instance expected, got %r" % (
    12 TypeError: 'ProductImage' instance expected, got 100
     16TypeError: 'ProductImage' instance expected, got 1
    1317
     18class Product(m.Model):
     19    ...
     20
     21class ProductImage(m.Model):
     22    product = m.ForeignKey(
     23        Product,
     24        on_delete=m.CASCADE,
     25        related_name='images',
     26    )
     27}}}
Back to Top