tags:

views:

16

answers:

0

Hi all,

In my userprofile model, I have a method (turned into a property) that returns a queryset based on another model's custom manager.

Concretely, a user can sell non-perishable and perishable items, and on the Item model level, several custom managers live that contain the logic (and return the querysets) for determining whether an item is perished or not. Within the userprofile, a method lives that returns something similar to:

Item.live_objects.filter(seller=self.user), 

where non_perished_objects is one of the said custom managers.

If however an item is added, it is never reflected through these userprofile methods. Only when restarting the server (and the queryset caches being refilled) are the results correct.

Is there a way to force Django to reload the data and drop the cached data?

Thanks in advance!

Update:

class LiveItemsManager(models.Manager):

    kwargs = {'perished': False,
              'schedule__start_date__lte': datetime.datetime.now(),
              'schedule__end_date__gt': datetime.datetime.now()}

    def get_query_set(self):
        return super(LiveItemsManager, self).get_query_set().filter(**self.kwargs)

class Item(models.Model):
    live_objects = LiveItemsManager()
    perished = models.BooleanField(default=False)
    seller = models.ForeignKey(User)

As you see, there's also a Schedule model, containing a start_date, an end_data and an item_id field.

In the UserProfile model, I have:

def _get_live_items(self):
    results = Item.live_objects.filter(seller=self.user)
    return results

live_items = property(_get_live_items)

The problem is that when calling the live_items property, the results returned are only the cached results.

(PS: Don't mind the setup of the models; there's a reason why the models are what they are :))