pymodm do not recognised the objects of a model - python

I have started using pymodm in my project (https://github.com/ypriverol/biocontainers-backend/blob/master/biocontainers/common/models.py). All CRUD operations work very well.
However, when I try to retrieve the list of objects for a specific MongoModel using the objects call:
tool_versions_dic = MongoToolVersion.objects.all()
I got this error:
AttributeError: type object 'MongoToolVersion' has no attribute 'objects'

Related

'ManyToManyDescriptor' object is not callable while copying M2M relation

I have this relation defined in x\research.py file.
research_groups = models.ManyToManyField(ResearchGroup, related_name='researchs', blank=True,
through='ResearchResearchGroups')
Then i want copy it to y\research.py file with
research.research_groups.set(Research.research_groups.all())
And while im trying to use it i get
'ManyToManyDescriptor' object is not callable
How can i handle assigning m2m relation to another place?

How do i find mongodb collection and update multiple fields using pymongo

This is the code snippet
send = mongo.db.subscription
send.find().update({'$set':{'status': "expired"}})
this is the output i get
send.find().update({'$set':{'status': "expired"}})
AttributeError: 'Cursor' object has no attribute 'update'
The syntax you want is:
send.update_many({<filter_condition>}, {'$set':{'status': "expired"}})

AttributeError: 'CollectionReference' object has no attribute 'orderBy'

I'm trying to order a firestore collection by the field name, but it's giving me this error: AttributeError: 'CollectionReference' object has no attribute 'orderBy'.
My code:
participants_ref = db.collection("participants")
docs = participants_ref.orderBy("name").stream()
In case this helps, I've also printed out participants_ref and I get the following:
<google.cloud.firestore_v1.collection.CollectionReference object at 0x0000021C9EAB7F40>
According to the documentation, the method you're looking for is order_by. Be sure to switch the code language tab to "Python" to see the correct usage.
docs = participants_ref.order_by("name").stream()
Also see the python API documentation for CollectionReference.

SQLAlchemy 'Comparator' object has no attribute 'has_key'

I am working with JSON SQLAlchemy column and my query statement needs the 'has_key' attribute, but apparently my 'Comparator' object doesn't have this attribute.
Transaction.query.filter(Transaction.fields.has_key('issuername')).all()
where Transaction.fields is a Column(JSON). I get error "AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with Transaction.fields has an attribute 'has_key'". My SQLAlchemy is latest version 1.09. Am I building this query wrong?
has_key operator is specific to JSONB
The JSONB type includes all operations provided by JSON, including the
same behaviors for indexing operations. It also adds additional
operators specific to JSONB, including JSONB.Comparator.has_key(),
JSONB.Comparator.has_all(), JSONB.Comparator.has_any(),
JSONB.Comparator.contains(), and JSONB.Comparator.contained_by().
For JSON column you can use -> PostgreSQL operator (get JSON object field by key)
Transaction.query.filter(Transaction.fields.op('->')('issuername')!=None).all()

Django serializer gives 'str' object has no attribute '_meta' error

I am trying to make Django view that will give JSON responce with earliest and latest objects. But unfotunately it fails to work with this error.
'str' object has no attribute '_meta'
I have other serialization and it works.
Here is the code.
def get_calendar_limits(request):
result = serializers.serialize("json", Session.objects.aggregate(Max('date'), Min('date')), ensure_ascii=False)
return HttpResponse(result, mimetype="application/javascript")
Thanks a lot beforehand.
I get the same error when trying to serialize an object that is not derived from Django's Model
Python has "json" module. It can 'dumps' and 'loads' function. They can serialize and deserialize accordingly.
Take a look at the following:
objects= Session.objects.aggregate(Max('date'), Min('date'))
print [ type[o] for o in objects ]
result = serializers.serialize("json", objects, ensure_ascii=False)
You might want to just run the above in interactive Python as an experiment.
What type are your objects? Is that type serializable?

Categories