On 20 nov, 21:54, RajeshD <[EMAIL PROTECTED]> wrote: > > That's interesting, but I think that leaving the models untouched > > would be better. > > Do you think there is a different way? > > There might be. First, you'd have to explain what you didn't like > about doing queries like: > > Image.objects.filter( book__library_owner=request.user) > > Since you don't want to change your models, only your Library model > maintains the source of ownership and so, by definition, all your > queries would have to lead to a check on the Library.owner field > thereby ending up with filters like xyz__library_owner=some_user.
Is not that I don't want to use: Image.objects.filter( book__library_owner=request.user) but I can't use it if I want to create a generic funtion, because depending of the distance from the model to the model who has the owner field, it can be: Image.objects.filter( book__library_owner=request.user) or Book.objects.filter( library_owner=request.user) I pass the module to the function: very roughly: def list_items_by_owner( module, parent_id ): for field in module._meta.fields: if field.name == 'owner': return True for field in module._meta.fields: if field.rel and not field.null: parent = field.rel.to new_parent_id out = list_items_by_owner( parent, new_parent_id) ... Anyway, what I'm trying to get is quite complicated and the code above is not correct at all, it was only for trying to explain what I want. I think I need somethig similar to django.db.query.fill_table_cache but I'm not sure. This could be used as a row-level permissions. it has some inconvenient because depending on the number of ForeignKeys, the recursive function might take longer. I'm pretty sure I didn't explain myself clear, I do my best :-) Thank you. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---