-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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 #21832 #2880
Fixed #21832 #2880
Conversation
buildbot, test this please. |
@timgraham @cjerdonek |
|
||
def create_username_instance(self, model): | ||
inputs = {} | ||
for f in model._meta.fields: |
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.
I think this should be model._meta.local_fields
. I will change it.
@timgraham |
Both places looks fine, but we should make the call to |
I will add another parameter |
@@ -88,19 +88,16 @@ def handle(self, *args, **options): | |||
verbose_field_name = self.username_field.verbose_name | |||
while username is None: | |||
if not username: |
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.
I am going to remove this condition as I think that its not required. The while loop already checks username is None
so just after that there is no need for if not username
.
Tests pass. They fail only in one because of checkout problem. |
@timgraham @cjerdonek |
It's hard for me to evaluate the patch right now without digging into |
@cjerdonek |
Okay, if that's the case, then looks good. Thanks a lot for working on this! |
@@ -87,20 +87,13 @@ def handle(self, *args, **options): | |||
# Get a username | |||
verbose_field_name = self.username_field.verbose_name | |||
while username is None: | |||
input_msg = capfirst(verbose_field_name) + ' (%s.%s)' % (self.username_field.rel.to._meta.object_name, self.username_field.rel.field_name) if self.username_field.rel else '' | |||
if default_username: | |||
input_msg = "%s (leave blank to use '%s')" % ( |
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.
use +=
By the way, in my previous comment when I said "looks good," I didn't mean to suggest that I reviewed the patch (which Tim is doing). Thanks, Tim. |
@@ -1456,6 +1456,9 @@ it when running interactively. | |||
Use the ``--database`` option to specify the database into which the superuser | |||
object will be saved. | |||
|
|||
Override ``get_input_data(self, field, message, default=None)`` if you want to |
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.
.. versionadded:: 1.8
You can subclass the management command and override get_input_data() if you want to customize data input and validation. Consult the source code for details on the existing implementation and the method's parameters. For example, it could be useful if you have a ForeignKey in REQUIRED_FIELDS and want to allow creating an instance instead of entering an existing instance's primary key.
…FK after 9bc2d76. Refactored code to allow overriding for custom behaviour. Thanks Chris Jerdonek and Tim Graham for review.
buildbot, test this please. |
if default_username: | ||
input_msg += " (leave blank to use '%s')" % default_username | ||
username_rel = self.username_field.rel | ||
input_msg = force_str('%s%s: ' % (input_msg, |
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.
In order to shorten this, I felt that it would be better to use a variable username_rel
= self.username_field.rel
rather than using it thrice.
merged in 75ff7b8. |
1st commit: Updates code, tests and docs.
2nd commit: Way to create fk instance at command line.