Why does the database remain static when a user enters the django shell via python manage.py runserver? For example:
>>> from userprofile.models import UserProfile
>>> up=UserProfile.objects.get(id=4)
>>> up.get_jobs_applied_for()
[<JobApplication: david - Editor>, <JobApplication: david - Assistant Director>]
# delete entries in the mysql database
>>> up.get_jobs_applied_for()
[<JobApplication: david - Editor>, <JobApplication: david - Assistant Director>]
# but the results do not reflect that
And the method being called:
# in `UserProfile` class
def get_jobs_applied_for(self):
jobs_applied_for = self.jobapplication_set.order_by('-timestamp')
return jobs_applied_for
Why doesn’t it query the db in real-time?
Django only populates a QuerySet the first time you do something that requires that the query be executed; after that, it keeps the same result set in memory. The order_by() doesn’t force another query to be executed against the database.