bug in bulk_create

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

bug in bulk_create

nima salemahim

Traceback (most recent call last):
  File "/usr/lib/python3.7/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "/home/nima/.virtualenvs/behtarino/lib/python3.7/site-packages/django/db/models/fields/related_descriptors.py", line 946, in add
    through_defaults=through_defaults,
  File "/home/nima/.virtualenvs/behtarino/lib/python3.7/site-packages/django/db/models/fields/related_descriptors.py", line 1150, in _add_items
    ])
TypeError: bulk_create() got an unexpected keyword argument 'ignore_conflicts'

hi i have three models

when i try to add on deal to one a category 

like : deal.categories.add(category)

i face error above can you help me about what the problem is ?

i dont know exactly it is django problem or django-ordered-model module problem

class Deal(ModificationLogMixin, models.Model):
title = models.CharField(max_length=160, blank=True, null=True)
description = models.TextField(blank=True, null=True)
initial_price = models.IntegerField(blank=True)
discounted_price = models.IntegerField(blank=True)
categories = models.ManyToManyField(
'deal.DealCategory',
related_name='deals',
blank=True,
through='DealCategoryThrough',
through_fields=('deal', 'dealcategory')
)
class DealCategory(OrderedModel):
business = models.ForeignKey(Business, related_name='deal_categories',
on_delete=deletion.CASCADE)
name = models.CharField(max_length=100, blank=True, null=True)
order_with_respect_to = 'business'
class DealCategoryThrough(OrderedModel):
deal = models.ForeignKey('deal.Deal', on_delete=models.deletion.CASCADE,
related_name='ordered_deals')
dealcategory = models.ForeignKey(DealCategory, on_delete=models.deletion.CASCADE,
related_name='ordered_deals')
order_with_respect_to = 'dealcategory'

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d8e04200-2f6f-4cf8-a315-30bb33ea761bo%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: bug in bulk_create

Jakub Stawowy
That's happened in Django 3.x when Method 'add' is used with many-to-many relations if intermediate model is used. consider call it on intermediate model manager like `DealCategoryThrough.objects.create(deal=deal, dealcategory=category)`


wtorek, 4 sierpnia 2020 o 14:10:15 UTC+2 nima salemahim napisał(a):

Traceback (most recent call last):
  File "/usr/lib/python3.7/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "/home/nima/.virtualenvs/behtarino/lib/python3.7/site-packages/django/db/models/fields/related_descriptors.py", line 946, in add
    through_defaults=through_defaults,
  File "/home/nima/.virtualenvs/behtarino/lib/python3.7/site-packages/django/db/models/fields/related_descriptors.py", line 1150, in _add_items
    ])
TypeError: bulk_create() got an unexpected keyword argument 'ignore_conflicts'

hi i have three models

when i try to add on deal to one a category 

like : deal.categories.add(category)

i face error above can you help me about what the problem is ?

i dont know exactly it is django problem or django-ordered-model module problem

class Deal(ModificationLogMixin, models.Model):
title = models.CharField(max_length=160, blank=True, null=True)
description = models.TextField(blank=True, null=True)
initial_price = models.IntegerField(blank=True)
discounted_price = models.IntegerField(blank=True)
categories = models.ManyToManyField(
'deal.DealCategory',
related_name='deals',
blank=True,
through='DealCategoryThrough',
through_fields=('deal', 'dealcategory')
)
class DealCategory(OrderedModel):
business = models.ForeignKey(Business, related_name='deal_categories',
on_delete=deletion.CASCADE)
name = models.CharField(max_length=100, blank=True, null=True)
order_with_respect_to = 'business'
class DealCategoryThrough(OrderedModel):
deal = models.ForeignKey('deal.Deal', on_delete=models.deletion.CASCADE,
related_name='ordered_deals')
dealcategory = models.ForeignKey(DealCategory, on_delete=models.deletion.CASCADE,
related_name='ordered_deals')
order_with_respect_to = 'dealcategory'

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/63929fc3-db58-41b1-b142-f16822ed4f44n%40googlegroups.com.