I want to use a non default database with ManyRelatedManager's set method in django.
I have tried the following methods:
By mentioning the using method in the query
It gives me the following error:
AttributeError: 'QuerySet' object has no attribute 'set'
By using the db_manager with the relatedmanager like this: modelA.modelB_set.db_manager('new_db').set(modelB_list)
This doesn't give any error, but it uses the default database to do this.
Is there any way that I can use a non default database with set method of ManyRelatedManager? Thanks in advance.
Related
I have recently tried to use Great expectations in a data creation pipeline but I run into a problem with validator object.
I followed this tutorial to set things up: https://docs.greatexpectations.io/docs/deployment_patterns/how_to_use_great_expectations_in_databricks/
I created my validator instance with following:
validator = context.get_validator(
batch_request=batch_request_1,
expectation_suite_name=expectation_suite_name,
)
Then I tried to set some expectations manually or with profiler but got those errors:
validator.expect_column_values_to_not_be_null(column="col")
AttributeError: 'Validator' object has no attribute 'expect_column_values_to_not_be_null'
profiler = UserConfigurableProfiler(profile_dataset=validator)
AttributeError: 'Validator' object has no attribute 'expect_column_values_to_be_in_type_list'
It looks like my instance does not have those methods and indeed when I hit tab to check what options I have with validator there are many other expect_column_.... But none of those 2.
Can you please advise me how to fix my validator object?
To select a specific database you write either:
Object.objects.using('other_db')...
or:
Object.objects.db_manager('other_db')...
Both seem to work completely fine. So what is the difference between both?
EDIT
I mean - should I always use the 'db_manager('other_db')' which would cover all cases for the 'using('other_db')' statement?
It depends on your situation. If you don't use any manager method then using() is fine, otherwise you will need db_manager().
You can select the database for a QuerySet at any point in the QuerySet “chain.” Just call using() on the QuerySet to get another QuerySet that uses the specified database.
But if you need to use manager methods, this will not work.
The following explanation is taken from the docs:
Say you have a custom manager method that touches the database – User.objects.create_user(). Because create_user() is a manager method, not a QuerySet method, you can’t do User.objects.using('another_db').create_user(). The create_user() method is only available on User.objects, the manager, not on QuerySet objects derived from the manager. The solution is to use db_manager(), like this:
User.objects.db_manager('another_db').create_user(...)
db_manager() returns a copy of the manager bound to the database you specify.
I'm using widgets.AdminSplitDateTime in a create view that is corresponding to a datetime field.
When I try to create the object it gives me the following error:
RemovedInDjango19Warning: Using SplitDateTimeWidget with DateTimeField is deprecated. Use SplitDateTimeField instead.
I have searched the web for an answer about how to use it but I couldn't find anything that works..
I tries to change the widgets.AdminSplitDateTime to forms.SplitDateTimeField and it gave me the following error:
'SplitDateTimeField' object has no attribute 'is_hidden'
can someone help me on figuring out how to use it?
Currently my Ember-cli application calls my API in this way:
apiurl:3000/ingredients?name=something
apiurl:3000/ingredients?filter=som?limit=10
I'd like to make Ember query for:
apiurl:3000/ingredient/something
apiurl:3000/ingredients/som?limit=10
But I've two problems:
WARNING: Encountered "ingredients" in payload, but no model was found for model name "ingredient" (resolved model name using myapp#serializer:application:.modelNameFromPayloadKey("ingredients"))
I can't find a way to make Ember use URL segments instead of query parameters.
I think I'm missing something?
Have you looked into overriding your RESTAdapter's buildURL method?
http://emberjs.com/api/data/classes/DS.RESTAdapter.html#method_buildURL
As what you're trying to do appears to be quite specific you could use this method to override the building of these requests, while at the same time keeping the default Ember model/params implementation the same.
I already create properties and add them to property group.Then I assign to my new product.But django show me
TypeError at /manage/update-product-properties/1
save() got an unexpected keyword argument 'using'
Yeah, as you point out in your comment to your OP, the problem went away by using a different version of Django. using is part of the machinery for multi-database support in Django 1.2