Chemical-Curation / chemcurator_django

Backend services for chemical curation
https://api.chemreg.epa.gov
MIT License
1 stars 0 forks source link

138 substance relationship model #184

Closed michael-barbour closed 3 years ago

michael-barbour commented 3 years ago

closes #138

The majority of these changes are the due to the deletion of test_models.py in favor of test_models/test_{{model_name}}.py

The migration looks a little odd due to the way we are splitting it into sprints forcing me to delete and remake, but all of the same content is there.

This is a self referential many to many relationship. I followed this guy's blog explaining how to set those up in django. I've attempted to test the added model functions as thoroughly as possible. Ideally these relationships should be abstracted in a way that the add_relationship(), remove_relationship(), get_relationship() and get_related_to() functions are all that is needed to deal with most relationship interactions.

After talking with @mcovalt I've opted out of using the many-to-many field entirely, due to this relationship being outside what this field would typically expect. I've maintained "relationships" and "related_to" as reverse lookup names to SubstanceRelationship but navigation will be entirely based on QuerySet with creation and deletion being managed by directly creating SubstanceRelationship instances