In my userprofile model, I have a method (turned into a property) that returns a query based on another user model manager.
Specifically, the user can sell not perishable and perishable elements, but at the level of the Element model, several user managers live that contain logic (and return requests) to determine whether the item died or not. Inside userprofile, a method is used that returns something similar:
Item.live_objects.filter(seller=self.user),
where non_perished_objects is one of the specified user managers.
If, however, an element is added, it is never reflected in these userprofile methods. The initial results are repeated only when the server is restarted (and filling the request caches).
Is there a way to get Django to reload the data and delete 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 can see, there is also a Schedule model containing the start_date, end_data and item_id fields.
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 you call the live_items property, the returned results are only cached results.
(PS: Do not pay attention to setting up models, there is a reason why the models are so :))