Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding convenience methods for getting or creating objects #220

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

gsnyder2007
Copy link
Contributor

Finally getting back to providing these convenience methods for,

  1. Getting an object by a field value, e.g. name="the name" or versionName="the version name" or etc
  2. Getting or Creating an object by a field value, e.g. name="the name" and if one doesn't exist, create it

@admacdonald1 you will recognize your suggested code for the get_resource_by() method. I've also attempted a get_or_create_by() and have included some sample code that uses it - see crud_project.py, crud_version.py, and update_version_settings.py (all in the .../examples/client folder).

I set the version for this proposal to v1.1.0 since it's a minor improvement to the actual interface (as opposed to a simple fix).

Let me know your thoughts.

Copy link
Collaborator

@OffBy0x01 OffBy0x01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andrew here (in case you don't recognize the updated username) - looks good to me @gsnyder2007.

return filtered[0] if filtered else None

def get_or_create_resource(self, field, value, name, parent=None, **kwargs):
resource = self.get_resource_by(field, value, name, parent, **kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking at this again - think there should be more here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, yeah, makes me wonder how my tests even worked. Investigating....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some code got borked in transit. Fixing...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed an update with the (I think) now complete code. Still testing....

@gsnyder2007 gsnyder2007 requested review from OffBy0x01 and removed request for admacdonald1 September 15, 2022 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants