Re: Update _id field before .save() for ForeignKey

2019-11-30 Thread Dvenum
Thanks, its interest to know more about pk management, but this is another case. Now I update pk for child objects and this is fastest way, what I found. If django will reread .pk before save, it will the same. Want to know, maybe my logic can be altered from the start. How peoples create batch

Re: Update _id field before .save() for ForeignKey

2019-11-30 Thread Integr@te System
Hi , Please lookandfeel on Moving an object from one database to another¶ https://docs.djangoproject.com/en/2.0/topics/db/multi-db/#moving-an-object-from-one-database-to-another On Sat, Nov

Re: Update _id field before .save() for ForeignKey

2019-11-30 Thread Dvenum
Integr@te System, This is True: id(company) == id(company_value.company) So, we have exact the same object company, .id is ready on .save() call, but internal meta dictionary still has None, because it was none when company_value created. On Sat, Nov 30, 2019 at 2:39 PM Integr@te System wrote:

Re: Update _id field before .save() for ForeignKey

2019-11-29 Thread Integr@te System
Hi Dvenun, Bc of Django implement accord to python, of cause child inherit from parent existence. https://docs.python.org/3.7/library/functions.html#id On Sat, Nov 30, 2019, 13:30 Dvenum wrote: > Interest idea and it works, but not necessary: > company = Company() > #company.id is

Re: Update _id field before .save() for ForeignKey

2019-11-29 Thread Dvenum
Interest idea and it works, but not necessary: company = Company() #company.id is None companies.append(company) Company.objects.bulk_create(companies) #company.id is 1 Instead to ask pk from database, it can be used from company_value.company.id. Django save pk value to

Re: Update _id field before .save() for ForeignKey

2019-11-29 Thread Charles Lee
I have an idea. 1. `bulk_create` all companies. 2. `Filter`(SELECT) all `Company` and make it dictionary for retrieving company fast. 3. 1. company_dict = { ’Name’: ‘pk’, ... } 4. Create a list of `CompanyValue` with company name and company_dict.

Re: Update _id field before .save() for ForeignKey

2019-11-29 Thread Charles Lee
I have an idea. 1. `bulk_create` all companies. 2. `Filter`(SELECT) all `Company` and make it dictionary for retrieving company pk fast. 3. 1. company_dict = { ’Name’: ‘pk’, ... } 4. Create a list of `CompanyValue` with company name and

Re: Update _id field before .save() for ForeignKey

2019-11-29 Thread Dvenum
Integr@te System, thanks. If I set pk (id) manually, it works, but hard to specify this id value. Maybe for one thread this way is good. On Fri, Nov 29, 2019 at 10:59 PM Integr@te System wrote: > Hi guy, > > I see this doc fix for u, with builtin pk in models django. > And you can create index

Re: Update _id field before .save() for ForeignKey

2019-11-29 Thread Integr@te System
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. https://docs.djangoproject.com/en/dev/ref/databases/#manually-specified-autoincrement-pk On Fri, Nov 29, 2019, 19:41 Maxim Bulatov wrote: > Hello, > > I