40👍
✅
For collectstatic:
message.append(
'Are you sure you want to do this?\n\n'
"Type 'yes' to continue, or 'no' to cancel: "
)
if self.interactive and input(''.join(message)) != 'yes':
raise CommandError("Collecting static files cancelled.")
So for collect static, if you set --no-input
it will set interactive
to False
and, as you can see above, will answer yes
to the question for you.
For migrate it is much trickier because of django signaling. The migrate
management itself does not ask any questions, but other installed apps may hook into the pre_migrate_signal
or post_migrate_signal
and handle interactivity in their own way. The most common one I know of is contenttypes
For contenttypes
, --no-input
answers “no” as in “No, please don’t delete any stale contenttypes”:
if interactive:
content_type_display = '\n'.join(
' %s | %s' % (ct.app_label, ct.model)
for ct in to_remove
)
ok_to_delete = input("""The following content types are stale and need to be deleted:
%s
Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.
Type 'yes' to continue, or 'no' to cancel: """ % content_type_display)
else:
ok_to_delete = False
👤2ps
Source:stackexchange.com