I think I have narrowed it down even further.  I print out the sql on
my development server, so in the terminal window I see whenever that
query is executed.  After I add a color, then go to the page with the
form that is supposed to load the colors, the sql is not printed out
to the terminal.  However, if I do a search on the website with a
different view that uses the same custom query I see the  sql get
printed out.  I've confirmed that a search view prints the sql, as
does another page.  The form page appears to be the culprit.  I tried
using the custom_query method of the manager on the same view as the
form and it outputs the sql as expected as well.  So the problem
appears to be using the custom_query method in the forms.py.
Apparently that only gets run once.  Is there a different way I should
populate the select?  Maybe in the view instead of in the form class?

Thanks for all of your help.

On Apr 4, 2:11 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Fri, Apr 4, 2008 at 1:19 PM, AJ <[EMAIL PROTECTED]> wrote:
>
> > 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?
>
> No, it's correct, the way it is written here the query will get executed
> each time the view calls custom_query().  So, is the view being called?
> Perhaps caching is interfering with the view returning current information?
>
> 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