What would be the proper way to make sure the code is run each time
the manager is called?  Here's a example of how I have my code
currently setup:

//models.py
from django.db import connection, models

class ColorManager(models.Manager):
  def custom_query(self):
    cursor = connection.cursor()
    query = """SOME QUERY HERE""
    cursor.execute(query)
    return [row[0] for row in cursor.fetchall()]

class Color(models.Model):
  color=models.CharField()
  objects=ColorManager()

//vews.py
from app.models import Color

def some_view(request):
  colors = Color.objects.custom_query()
  return render_to_response('page.html', {'colors' : colors})


Is this not the proper way to setup the code so that the manager's
custom_query get's run every time it is called?

Thanks,
Aaron

On Apr 4, 11:50 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Fri, Apr 4, 2008 at 11:46 AM, AJ <[EMAIL PROTECTED]> wrote:
>
> > So I have a manager for an model that executes some custom sql.  That
> > custom sql on a certain page populates a select dropdown.  For an
> > example we'll say that the select is a list of colors, and there is
> > also a page to add new colors.  If I add a new color then go to the
> > page that has the list of colors in the select the color I just added
> > doesn't appear.  It doesn't matter how many times I reload the page.
> > I need to manually restart the server and then the new color shows up
> > in the dropdown.  I went into the manager that creates the custom sql
> > and print out the sql.  I see it gets printed out the first time it is
> > used, but every other time after that it isn't printed until I restart
> > the server.  Therefore any new data from this query won't show up
> > until the server is restarted.
>
> > Any ideas why this query isn't run every time it is requested?
>
> Because you've specified it in some code that is only executed when the
> manager is defined (import time), not each time the manager is called.
>
> Karen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to