Hi guy,
I see this doc fix for u, with builtin pk in models django.
And you can create index in text/char field to optimize performance.
On Fri, Nov 29, 2019, 19:41 Maxim Bulatov <dvenum.at@gmail.com> wrote:
Hello,--
I have lot of lists like follow:
(Name1): (V1, V2, V3, V4, ..)
And I use many threads to create many db objects:
company = Company(Name)
for x in vector:
v = CompanyValue(company=company, value=x)
values.append(v)
class CompanyValue(models.Model):
company = models.ForeignKey('Company', on_delete=models.CASCADE)
value = FloatField
This pool of threads return all lists, what I combine, filter and want put to database in one bulk_create call.
Suddenly, I found, company.id is not ready to be linked in CompanyValue, follow code does not works:
Company.objects.bulk_create(companies)
CompanyValue.objects.bulk_create(values) # value.company_id is null here
No way to save objects in my threads, because I need to filter objects and can do it only when all of them are collected. Also, it has performance issues 100k+ of requests is slowly enough. I have two ways to resolve:
1. I can make intermediate class or tuple and create CompanyValue objects only when companies is saved to db. Hard to support, hard to filter, not so clean.
2. I can use dirty hack to update _id field:
for v in values:
v.company = v.company
Can you advice more ways for me? It seems, I don't know something from django features to make it elegant.
I see 11 years old issue here (https://code.djangoproject.com/ticket/9553) and it marked as intended behaviour.
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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3d62beaf-7fbf-492f-b998-1539f45cd7a0%40googlegroups.com.
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 django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP5HUWrC747ZHLWPCf7UK%2BZvZRDAcxDMxk7ewE4d4UhZAHpB7g%40mail.gmail.com.
No comments:
Post a Comment