-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add JSONFileChildSeeder
class
#4
Conversation
The `JSONFileChildModelSeeder` new class extends `JSONFileModelSeeder` to contemplate cases where the model is a child of another model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all i should thank both of you for your contributions, i am so happy to see your commits
It is really really nice work and i like it
But I think there is redundancy in the code in this section
I find out that these two sections do the same thing and we can delete one of them
both of them get the needed object of a specific model with specific query data (dict) then store it in the hashmap and get it from it if it is requested again instead of getting it again from the database
first one between line 467 and line 477
if not related_keys_dict[k] in hashmap:
hashmap[related_keys_dict[k]] = dict()
tuple_v = _convert_to_tuple(v)
if tuple_v in hashmap[related_keys_dict[k]]:
entry[k] = hashmap[related_keys_dict[k]][tuple_v]
else:
entry[k] = _replace_item(v, related_keys_dict[k])
hashmap[related_keys_dict[k]][tuple_v] = entry[k]
second part between line 482 and line 491:
obj_pk = _convert_to_tuple(entry)
if not model in hashmap:
hashmap[model] = dict()
if obj_pk in hashmap[model]:
return hashmap[model][obj_pk]
hashmap[model][obj_pk] = model.objects.get(**entry)
return hashmap[model][obj_pk]
maybe i misunderstand the code
correct me if i am wrong
and thank you in advance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review!
You're absolutely correct! We changed our code to remove the redundancy ;)
… called in JSONFileChildSeeder
We propose an extension of
JSONFileModelSeeder
which can handle child models. It has been implemented with a caching system to speed up the seeding process.Also correct some minor typos.