-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Document the use of get_queryset
for RelatedField
#3605
Changes from 4 commits
f245293
fe12816
dca2de3
389b48e
a19f152
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,14 @@ def test_representation(self): | |
representation = self.field.to_representation(self.instance) | ||
assert representation == self.instance.name | ||
|
||
def test_no_queryset_init(self): | ||
class NoQuerySetSlugRelatedField(serializers.SlugRelatedField): | ||
def get_queryset(this): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @ticosax it indeed should be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe not, I need to dig this a bit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because I needed to get to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It perhaps would have been better to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored slightly in #3861 |
||
return self.queryset | ||
|
||
field = NoQuerySetSlugRelatedField(slug_field='name') | ||
field.to_internal_value(self.instance.name) | ||
|
||
|
||
class TestManyRelatedField(APISimpleTestCase): | ||
def setUp(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this now read "Relational field must provide a
queryset
argument, overrideget_queryset
, 'or set read_only=True
."?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a good idea.