views:

42

answers:

0

Basic model breakdown:

Movie and MovieGenre models. The Movie model has a field called genres, which is declared as:

genres = models.ManyToManyField(MovieGenre, blank=True)

Here is the issue:

In [42]: frank = Movie.objects.get(id=122)

In [43]: frank.genres.count()
Out[43]: 2

In [44]: frank.genres.all()
Out[44]: [<MovieGenre: Concert>, <MovieGenre: Horror>]

In [45]: for genre in frank.genres.all():
   ....:     print genre
   ....:
   ....:
Animals/Nature
Classic
Concert
Horror
Program
Suspense/Thriller
War

As you can see, I load the movie into the frank variable. The genres.count() and genres.all() print out correctly, but when I iterate over genres.all(), it prints out the old data. I have no clue where this is coming from, since this is all in the shell. I can look in the database, and the mappings are correct, only two for this movie, both the correct genre.

After 5-10 minutes, I can iterate over genres.all() again, without reloading anything, or doing anything else on the computer, and it will show the two, correct genres.

This is causing an issue in the admin on the site, because the form isn't reflecting changes. I thought it could be caching on the site, so I tried in the shell, and I get the same behavior.

  • Django 1.2.1
  • Python 2.6.5
  • Windows 7
  • Shell is ipython.
  • Using PostgreSQL for the backend.