1

I'm very new to python and django!

I've created a model that is syncing properly with my MySQL db instance:

class HelloWorld(models.Model):
    string = models.CharField(max_length=255)

    def __unicode__(self):
        return "Data: " + self.string

When I launch an interactive shell with

manage.py shell

I am able to view my models records with:

import print_string
HelloWorld.objects.all()
[<HelloWorld: Data: Hello there>]

What I'd like to be able to do is modify my model thusly:

    def __unicode__(self):
        return "This is my data now: " + self.string

...and then view this change immediately in my interactive shell.

How do I refresh/recompile my project so subsequent calls to:

HelloWorld.objects.all()

...would then return:

[<HelloWorld: This is my data now: Hello there>]

At the moment, the only way I can see to do this is to exit the shell, restart it and import my modules again, is there a way to refresh this on-the-fly?

Neil Trodden
  • 4,724
  • 6
  • 35
  • 55
  • See this question and answers: http://stackoverflow.com/questions/890924/how-do-you-reload-a-django-model-module-using-the-interactive-interpreter-via-m/3466579#3466579 tl;dr it's rather complex because django caches model imports for performance reasons. – Andrew Gorcester Mar 02 '13 at 23:40
  • 1
    Thanks Andrew, it's more complex than I thought. I think I could do with looking at this: http://stackoverflow.com/questions/1836361/how-do-i-preload-imports-into-djangos-manage-py-shell-command - so I could quickly restart a shell and be ready to play with my modified objects. – Neil Trodden Mar 03 '13 at 00:11
  • That sounds like a good solution. – Andrew Gorcester Mar 03 '13 at 00:58

0 Answers0