Index: django/core/management/commands/shell.py
===================================================================
--- django/core/management/commands/shell.py    (révision 9723)
+++ django/core/management/commands/shell.py    (copie de travail)
@@ -2,6 +2,14 @@
 from django.core.management.base import NoArgsCommand
 from optparse import make_option
 
+# XXX looks like we need it to be in globals
+# else the test on readline.get_completer fails ???
+try: 
+    import readline
+except ImportError:
+    pass
+
+
 class Command(NoArgsCommand):
     option_list = NoArgsCommand.option_list + (
         make_option('--plain', action='store_true', dest='plain',
@@ -34,26 +42,35 @@
             # that tab completion works on objects that are imported at runtime.
             # See ticket 5082.
             imported_objects = {}
-            try: # Try activating rlcompleter, because it's handy.
-                import readline
-            except ImportError:
-                pass
-            else:
-                # We don't have to wrap the following import in a 'try', because
-                # we already know 'readline' was imported successfully.
-                import rlcompleter
-                readline.set_completer(rlcompleter.Completer(imported_objects).complete)
-                readline.parse_and_bind("tab:complete")
 
-            # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system
-            # conventions and get $PYTHONSTARTUP first then import user.
+            # XXX if pythonrc already defines a (possibly better) completion,
+            # this screw up everything.
+            # so better to *first* load pythonrc, then test if it's necessary
+            # to add completion
             if not use_plain: 
                 pythonrc = os.environ.get("PYTHONSTARTUP") 
                 if pythonrc and os.path.isfile(pythonrc): 
-                    try: 
-                        execfile(pythonrc) 
+                    try:
+                        print "loading pythonrc file %s" % pythonrc
+                        execfile(pythonrc, imported_objects) 
                     except NameError: 
                         pass
                 # This will import .pythonrc.py as a side-effect
                 import user
+
+            # XXX
+            try: # Try activating rlcompleter, because it's handy.
+                readline
+            except NameError:
+                pass
+            else:
+                # XXX check if completer is already setup by the pythonrc
+                # else add a simple completion
+                if not readline.get_completer():
+                    # We don't have to wrap the following import in a 'try', because
+                    # we already know 'readline' was imported successfully.
+                    import rlcompleter
+                    readline.set_completer(rlcompleter.Completer(imported_objects).complete)
+                    readline.parse_and_bind("tab:complete")
+
             code.interact(local=imported_objects)
