0

I've been using django-notification (https://github.com/jtauber/django-notification.git) but the documentation is a little brief for a beginner.

I want to be able to have users keep a watch on searches (a results page with product listings) that have no results at the time of search. Then if a record is added that matches the search, the user should be notified.

I can't find any online explanation of how to use 'observe', which I think is what i'd need to use to watch for records appearing (in search results)? Perhaps, this is the wrong approach (using django-notification) as I need a signal to await the occurrence of a filter result that would initially contain no objects...

(the project is too developed to consider an option like Pinax to provide a template for things like this)


I suppose I need to evaluate

f=Products.objects.filter({search_request_args})
if f:
   notification.send([request.user], "product_match", {"from_user": settings.FROM_DEFAULT})

Perhaps as a chron job?

ChrisF
  • 134,786
  • 31
  • 255
  • 325
null
  • 1,137
  • 2
  • 11
  • 29

1 Answers1

1

It looks like you want to use django signals (see: https://docs.djangoproject.com/en/dev/topics/signals/)

let's say you want to watch the creation of Product objects

from django.db.models.signals import post_save
from my_app.models import Product

def new_product(sender, instance, created, **kwargs):
    # short-circuit the function if it isn't a new product (it's 
    # being updated not created)
    if not created: return

    # note: instance is the newly saved Product object

    if (check_if_the_new_product_matches_searches_here):
        notification.send(...)

post_save.connect(new_product, sender=Product)
Jiaaro
  • 74,485
  • 42
  • 169
  • 190
  • Thanks for the info- just concerned the (check_if_the_new_product_matches_searches_here) would be an expensive query to run each time someone adds a new_product.. I should have explained the new_product feature is available to all users. Many thanks. – null Aug 02 '11 at 16:43
  • @adam You could use celery to defer that processing so the response and return *before* the expensive queries are run. see: http://celeryproject.org/ – Jiaaro Aug 04 '11 at 16:52