Django's list_details views saving queryset to memory (not updating)? -
I have a custom model manager that looks like this:
class MyManager ( Model Manager) def get_query_set (self): '' 'Only get' approved 'items and ignore' pub_date 'which is in the past. '' 'Queryset = super (MyManager, itself) .get_query_set () queryset = queryset.filter (status__in = (' a ',)) return queryset.filter (pub_date__lte = datetime.utcnow ())
And it works well; However, I have a problem using Django's generic.list_detail
view object_detail
and object_list
: once And, for this reason, it is not bringing those items because it should be, because I think that utcnow ()
is called only once (when it is first loaded).
I believe it is deliberate and it enhances the performance - though, it means that to show videos elsewhere on the site (at places I not Before available in a object_detail
(see object_detail
(see urls.py below). This is leading to 404 ...
Any thoughts? Or to avoid this, do I have to write my custom ideas?
Thank you!
urls.py
url (r '^ video / (? P & lt; object_id & gt; \ d +) $', list_detail.object_detail, {' Queryset ': Video.objects.all ()}}, name =' video_detail ',),
This is not a cache problem: As you do, the query definition is evaluated once, while parsing the URL, and then, never evaluating it is done.
The solution is really simple and is described in the online documentation: just create a small custom view, which will call the normal view.
I am actually using a lot of similar solutions and I think it is quite comfortable.
By the way, take a small note, I will suggest not using custom manager for this case, and return it to normal filtering.
Comments
Post a Comment