views:

97

answers:

1

I'm writing an app for tagging photos. One of the views handles adding new tags and without boilerplate for POST/GET and handling field errors it does this:

tagName = request.cleaned_attributes['tagName']
t = Tag.objects.create(name = tagName)
t.save()

Now in a view for another request to retrieve all tags I have:

tags = Tag.objects.all()

I see the data only after restarting Django development server, which is odd to me. Seems like Tag.objects.all() has some caching mechanism that is not invalidated properly? The data is for sure saved to the database.

The database backend is sqlite. I guess I am either missing some configuration or just forgot to do something simple. Ideas?

+3  A: 

Tag.objects.all() is a QuerySet. These do not hit the database until you do something to evaluate them. So, how exactly are you using it in your view? If you are using a generic view and passing the queryset through extra_context, for example, it wouldn't be re-evaluated.

Also, as an aside, Tag.objects.create(name = tagName) will automatically save to the db.

Jeff Bradberry