How to import related objects and their relationships.
See original GitHub issueWhen I import models like following:
class Category(models.Model):
name = models.CharField(max_length=100, db_index=True)
class Subcategory(models.Model):
name = models.CharField(max_length=100, db_index=True)
slug = models.SlugField(max_length=200, db_index=True)
category = models.ForeignKey(Category, blank=True)
class Product(models.Model):
name = models.CharField(max_length=100)
category = models.ForeignKey(Category, blank=True, null=True)
subcategory = models.ForeignKey(Subcategory, blank=True, null=True)
Everything is imported thanks to ForeignKeyWidget, but how can I import relations when my csv file looks something like that:
id | product_name | category | subcategory – | T-Shirt A | His | summer – | T-Shirt B | Her | summer
?
As you see ‘summer’ subcategory name isn’t unique and I need to set the proper relationship like:
‘His’ < ‘summer’ < ‘T-Shirt A’ ‘Her’ < ‘summer’ < ‘T-Shirt A’
during import.
How can I achieve it?
I will be grateful for your help.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Migrate data from one organization to another - Salesforce Help
The easiest way to do this is using Excel's VLOOKUP function to add the new record Ids to your files for import.
Read more >Import and Export records with lookup or master detail ...
Hello Trailblazers, In this video we're going to learn how we can import or export records with lookup or master detail relationships in ......
Read more >Import Your Relationship Data - Oracle Help Center
Attribute Description Prerequisite Setup Task/ Import V...
StartDate The date when the relationship was created. This should be a valid date.
EndDate The date when...
Read more >How to preserve relationships upon data import?
First you can't import primay Ids in Salesforce. They are always automatically generated on insert. For the relation you need to export the ......
Read more >Salesforce Object Relationships - Workato Docs
An object relationship in Salesforce is a two-way association between two objects. Relationships are created by creating custom relationship fields on an object...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have solved this in my current project (for importing ManyToMany Values) with subclassing
import_field
and calling aclean_FOO
method (adapted the code fromdehydrate_FOO
). Within the clean method (example here are ManyToMany fieldsdisks
andfilesystems
) you can get the correct subcategory or create the instance with Django’sget_or_create
method (Careful about the return values here).This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.