hi,

i am creating a very simple board and wanted to add a method to my
models which would check if there are any new posts in a thread /
forum for a given user.. for this to work .. i obviously need the
currently logged in user in my models ..

but i didn't want to iterate through all my models in my view, since i
used the django.views.generic.list_detail.object_list which does the
paging and everything for me ..

so i thought the easiest way would be to allow adding of custom
initializers.. which would be called once a model was created by
django.db.models.query.QuerySet .. so i played around a little until
it worked for me: http://yourhell.com/~kahless/query_initializers_patch.diff

the usage is quite simple:
class MyModelInitializer(object):
  def __init__(self, request):
    self.request = request

  def init_model(self, model):
    model.do_init( self, self.request.user )

(my models would have a 'do_init' method which takes the user and
stores it internally)

the object_list would then get a queryset argument in my view like:
queryset =
Post.objects.filter( ..... ).add_initializer( MyModelInitializer( request ) )

and my templates could simply call {% if thread.hasNewPosts %} ...

so .. is this a clean solution ? or can this be done differently ?
and .. would there any chance this patch could find it's way into
django or does it break any main design philosophy ?

- i'm very new to python and django alike .. so there might be an
obvious other solution.

thanks & cu,
  Herbert Poul


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to