Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
Hi everyone!
I'm stuck with getting unique values while using CSV importer module. I'm trying to import a csv list of books, like <title>, <year>, <author> and populate two clonable templates, <books> and <authors>. But in <authors> I need only one of each author from CSV file, in order to make a relation between those templates. For example, consider the following list:

Dark Carnival, 1947, Ray Bradbury
Fantastic Voyage, 1966, Isaac Asimov
The Long Rain, 1950, Ray Bradbury


I would like to have 3 pages (books) and only 2 authors (Bradbury, Asimov). Any suggestion would help... :oops: Thanks a lot!
A practical idea is to keep Author as a text field. Establish relations later via a separate one-time-run code, using data in the text field. CSV import will be quicker and will not depend on a complex subroutine.

It is handy to keep a list of cloned Authors as IDs of pages in an array. Avoid comparing strings by storing a hash of the full author name (md5 or whatever) as array key with two values - ID of its page and a name (merely for reference).

My Documentation, Addons, Functions.
Join COUCH:TALK telegram channel
Hi Anton, thanks for the tip(s), but a more "Couchified" solution, even is a little slower, is what I was looking for. Thanks again!
Dan, I can see you prefer the "couchified" tips :)
Maybe this one will help. You would need only to fill the missing bits.

https://pastebin.com/gqHzdinV

Use the md5 tag viewtopic.php?f=8&t=10115&p=23922#p23922

KK: for some reason I get 500 Server Error on sending that code in reply. Please check :)

My Documentation, Addons, Functions.
Join COUCH:TALK telegram channel
KK: for some reason I get 500 Server Error on sending that code in reply. Please check

Thanks for the heads-up, Anton.
I believe it is some 'server hardening' mod going paranoid on something in the code..

Anyway, I am copying and attaching your code as a zip file for posterity :)

Attachments

5 posts Page 1 of 1