How To Capture A Field Instance During Django-import-export Upload
I'd like to import data into my resource minus the school field because the logged in user already belongs to a specific school. How would I do it without having the school field i
Solution 1:
Either remove 'school' from your 'fields' declaration, or add it to the 'exclude' list.
Edit
To include a school_id
which is associated with the logged in user, you'll need to create the Resource with this school_id
:
class ImportStudentsResource(resources.ModelResource):
def __init__(self, school_id):
super().__init__()
self.school_id = school_id
def before_save_instance(self, instance, using_transactions, dry_run):
instance.school_id = self.school_id
post()
def post(self, request):
# skipped existing code
school_id = get_school_id_from_logged_in_user(self.request)
resource = ImportStudentsResource(school_id)
Post a Comment for "How To Capture A Field Instance During Django-import-export Upload"