You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In simplest use case, there is no issue with both setups.
But I encountered issues while using custom queryset and manager classes that inherit from HStoreManager and HStoreQuerySet. I'd like the following code to work:
classCustomQuerySet(hstore.HStoreQuerySet):
defcustom_query(self):
"""A custom method for both manager and queryset."""classCustomManager(hstore.HStoreManager):
defcustom_manager(self):
"""A custom method for manager only."""classCustomModel(models.Model):
objects=CustomManager.from_queryset(CustomQuerySet)()
Is the code above valid?
If it is valid, then I think there is a bug in django-hstore: CustomModel.objects.custom_query raises some 'HStoreQuerySet' object has no attribute 'custom_query' error.
I guess that this is because HStoreManager.get_queryset() returns HStoreQuerySet whereas in my case I want it to return CustomQuerySet. So I had to alter CustomManager like that:
link between HStoreManager and HStoreQuerySet should be setup in model, typically using objects = hstore.HStoreManager.from_queryset(hstore.HStoreQuerySet)() (but could be adapted if users have custom manager and/or custom queryset) => documentation to be updated
for backward compatibility, current HStoreManager.get_queryset should be renamed to HStoreManager.get_query_set()
The text was updated successfully, but these errors were encountered:
As explained in https://docs.djangoproject.com/en/1.7/topics/db/managers/#from-queryset, when we have a custom manager and queryset classes, we can use manager's
from_queryset()
method.Does this pattern apply here? I mean, in order to setup a model, the documentation currently tells:
Shouldn't it be something like this instead?
In simplest use case, there is no issue with both setups.
But I encountered issues while using custom queryset and manager classes that inherit from HStoreManager and HStoreQuerySet. I'd like the following code to work:
Is the code above valid?
If it is valid, then I think there is a bug in django-hstore:
CustomModel.objects.custom_query
raises some'HStoreQuerySet' object has no attribute 'custom_query'
error.I guess that this is because HStoreManager.get_queryset() returns HStoreQuerySet whereas in my case I want it to return CustomQuerySet. So I had to alter CustomManager like that:
As I understand, things to change would be:
objects = hstore.HStoreManager.from_queryset(hstore.HStoreQuerySet)()
(but could be adapted if users have custom manager and/or custom queryset) => documentation to be updatedThe text was updated successfully, but these errors were encountered: