Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use model error_messages when available#3435

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lovelydinosaur merged 1 commit intoencode:masterfromstianjensen:unique-error
Sep 24, 2015
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletionrest_framework/utils/field_mapping.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -193,7 +193,15 @@ def get_field_kwargs(field_name, model_field):
]

if getattr(model_field, 'unique', False):
validator = UniqueValidator(queryset=model_field.model._default_manager)
unique_error_message = model_field.error_messages.get('unique', None)
if unique_error_message:
unique_error_message = unique_error_message % {
'model_name': model_field.model._meta.object_name,
Copy link

Choose a reason for hiding this comment

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

django usescapfirst forverbose_name would such change be accepted?

egoag reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

Most probably yup! (Could you point out an example ofexactly where/what first tho?)

Copy link

Choose a reason for hiding this comment

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

I'm not sure what you would like to see. Is itthis?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect, yup. If you do choose to submit a fix for this it'll also be worth double checking if there's any other errors messages where we should also be doingcapfirst(opts.verbose_name).

Choose a reason for hiding this comment

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

can it filter OneToOneField?

'field_label': model_field.verbose_name
}
validator = UniqueValidator(
queryset=model_field.model._default_manager,
message=unique_error_message)
validator_kwarg.append(validator)

if validator_kwarg:
Expand Down
2 changes: 1 addition & 1 deletiontests/test_validators.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,7 @@ def test_is_not_unique(self):
data = {'username': 'existing'}
serializer = UniquenessSerializer(data=data)
assert not serializer.is_valid()
assert serializer.errors == {'username': ['This field must be unique.']}
assert serializer.errors == {'username': ['UniquenessModel with this username already exists.']}

def test_is_unique(self):
data = {'username': 'other'}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp