Menu
  • HOME
  • TAGS

select_related with reverse foreign keys

django,django-models,django-queryset,django-managers

Yes, that is what prefetch_related() is for. It will require an additional query, but the idea is that it will get all of the related information at once, instead of once per Person. In your case: qs.select_related('position__report_to') .prefetch_related('position__report_to__person_set') should require two queries, regardless of the number of Persons in the...

Django, Custom Managers affect save method?

django,django-models,django-admin,django-managers

It cannot be done! As inancsevinc pointed out, save() calls on the default manager. The Django docs mention that get_query_set should not be modified on default managers, and I have sadly found out why. Hopefully in the future relatedManagers can be specified/controlled, but for now this method will not work...

Complex queryset with annotate across different models

django,django-queryset,django-managers

I believe that something similar to Room.objects.filter(hospitalization__date_out="2014-04-25", max_persons__lt=x) should do the trick. Remember that you can have multiple declarations in a filter operation, and that you can also chain both exclusions and filters. This doesn't add to database activity; queryset filters and the like are only executed when the queryset...

How to use a Managers to save data in Django

python,django,django-models,django-managers

I believed both are fine. However, I prefer to abstract all of the business logic such that we don't even have to know how logging of action is done. When calling log_action, I am hiding the implementation detail on what should be passed when. If I didn't use log_action, I...

How to pass parameteres to get_queryset method of django models manager?

django,django-models,django-managers

This should be what you are looking for: class ContextAwareNotificationsManager(models.Manager): def filter_user(self, user): return super(ContextAwareNotificationsManager, self).get_query_set().filter(...) ...

Test case give error object has no attribute '_meta'

python,django,django-managers

There's no reason why you can't set the model yourself. objects = ActionManager() objects.model = MyModel ...