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

Allow other lookups in ModelInstance #3

Merged
merged 1 commit into from May 19, 2016

Conversation

ulope
Copy link
Contributor

@ulope ulope commented May 18, 2016

Currently ModelInstance allows lookups only by pk. This PR adds support for arbitrary lookups by adding a lookup keyword argument.

Example:

@clik.option('--something', type=ModelInstance(SomeModel, lookup='name'))

(This PR is intended to be merged on top of the changes from #2 )

@GaretJax
Copy link
Owner

Looks good as well, but could you please rebase it on master?

P.S.: I wrote exactly the same change today (albeit on a different project with a backported ModelInstance)! :)

This makes `ModelInstance` accept a keyword argument `lookup` (that
defaults to 'pk') which allows to specify which lookup to use on the
given `QuerySet`.
@ulope
Copy link
Contributor Author

ulope commented May 19, 2016

Looks good as well, but could you please rebase it on master?

Done.

P.S.: I wrote exactly the same change today (albeit on a different project with a backported ModelInstance)! :)

Funny how often that happens :)

DummyModel.objects.create(slug='test')
expected = b'<DummyModel: 1>'

assert call_command('modelcmd', '--pk', '1').stdout == expected
Copy link
Owner

Choose a reason for hiding this comment

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

This is a bit fragile (e.g. when using --reuse-db), as the ID could change across runs. Would be better to use instance = DummyModel.objects.create(slug='test') and instance.pk.

@GaretJax GaretJax merged commit 10284ab into GaretJax:master May 19, 2016
@GaretJax
Copy link
Owner

Thanks for the PRs. I added this commit 6aeeb7b and merged.

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