Friday, August 28, 2020

Modeling a large dictionary with synonyms and searchable values

How to not use foreign key method for large dictionaries since key values
can't fulfill the unique constrain?

For smaller, static dictionaries I use choices field option, but this dictionary,
while I don't expect many changes, is large and have several values for a single
key. Users aren't supposed to know the key value for the dictionary (which is
defined outside of my model), so allowing them to search the description of
said key is helpful. The problem is that the same key, can have several values
(synonyms) which makes the foreign key method non-ideal. I could think
some ways to circumvent the unique constrain, like have a single table with
all key and another with key:values relationship, but most of them sounds too
complicated and makes more problems down the line, with the other requirements.

What I was thinking was using elasticsearch as a truth source and having a function
to return the unique key elements as a dict, but I'm unsure how to do that or if there
is a saner approach.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/366297ad-46d5-45cd-b78e-d054f2103eafn%40googlegroups.com.

No comments:

Post a Comment