The actual custom_query is called in forms.py, something similar to the following:
//views.py from app.forms import CrayonForm def add_crayon(request): if request.method == 'POST': form = CrayonForm(request.POST) if form.is_valid(): ... else: form = CrayonForm() return render_to_response('page.html', {'form' : form}) //forms.py from django import newforms as forms from django.newforms import widgets from app.models import Color class CrayonForm(forms.Form): colors = [('', 'Select a color...')] colors += [(c.id, c.name) for c in Color.objects.custom_query()] color = forms.Field(widget=widgets.Select(choices=colors), initial="") Is any sort of caching enabled by default? I haven't added/changed any settings involving caching in the settings.py 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 django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---