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

Fixed #29358 -- Added a system check to prohibit models with more than one primary key. #9911

Merged
merged 1 commit into from May 3, 2018

Conversation

hramezani
Copy link
Member

Add a system check to prohibit models with more than one primary_key field(ticket_29358)

@timgraham timgraham changed the title Add a system check to prohibit models with more than one primary_key Fixed #29358 -- Added a system check to prohibit models with more than one primary key. May 1, 2018
Copy link
Member

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

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

HI @hramezani.

This looks good thanks. Just a couple of comments.

@@ -1436,6 +1437,19 @@ def _check_property_name_related_field_accessor_clashes(cls):
)
return errors

@classmethod
def _check_primary_fields_clashes(cls):
Copy link
Member

Choose a reason for hiding this comment

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

I think this is a bit vague. Perhaps _check_single_primary_key.

@classmethod
def _check_primary_fields_clashes(cls):
errors = []
if sum([1 for f in cls._meta.local_fields if f.primary_key]) > 1:
Copy link
Member

Choose a reason for hiding this comment

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

You can just use a generator, without the [ and ] here:

if sum(1 for f in cls._meta.local_fields if f.primary_key) > 1:

@timgraham
Copy link
Member

The new message should also be added to docs/ref/checks.txt.

@hramezani
Copy link
Member Author

@carltongibson , @timgraham , thank you for the comments.
requested changes are done.

@carltongibson carltongibson merged commit 816b8d9 into django:master May 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants