Comments (9)
I owe you a beer!
from flask-mongorest.
Issues with the Document schema are now fixed, new error being returned.
from mongoengine import *
class Positive(EmbeddedDocument):
count = IntField()
peaks = StringField() # Temporary
class Negative(EmbeddedDocument):
count = IntField()
peaks = StringField() # Temporary
class AdductWeights(EmbeddedDocument):
negative = EmbeddedDocumentField(Negative)
positive = EmbeddedDocumentField(Positive)
neutral = FloatField()
class MetaboliteAdduct(Document):
meta = { "collection" : "metabolites"}
name = StringField()
adduct_weights = EmbeddedDocumentField(AdductWeights)
Now returns AttributeError: type object 'AdductWeights' has no attribute 'objects'
.
Traceback (most recent call last):
File "/home/keo7/.local/lib/python2.7/site-packages/flask/app.py", line 1994, in __call__
return self.wsgi_app(environ, start_response)
File "/home/keo7/.local/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/home/keo7/.local/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/keo7/.local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/home/keo7/.local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/keo7/.local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/keo7/.local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/home/keo7/.local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/keo7/.local/lib/python2.7/site-packages/flask/views.py", line 84, in view
return self.dispatch_request(*args, **kwargs)
File "/home/keo7/.local/lib/python2.7/site-packages/mimerender.py", line 244, in wrapper
result = target(*args, **kwargs)
File "/home/keo7/.local/lib/python2.7/site-packages/flask_mongorest/views.py", line 56, in dispatch_request
return self._dispatch_request(*args, **kwargs)
File "/home/keo7/.local/lib/python2.7/site-packages/flask_mongorest/views.py", line 68, in _dispatch_request
return super(ResourceView, self).dispatch_request(*args, **kwargs)
File "/home/keo7/.local/lib/python2.7/site-packages/flask_views/base.py", line 36, in dispatch_request
return super(View, self).dispatch_request(*args, **kwargs)
File "/home/keo7/.local/lib/python2.7/site-packages/flask/views.py", line 149, in dispatch_request
return meth(*args, **kwargs)
File "/home/keo7/.local/lib/python2.7/site-packages/flask_mongorest/views.py", line 107, in get
result = self._resource.get_objects(qfilter=qfilter)
File "/home/keo7/.local/lib/python2.7/site-packages/flask_mongorest/resources.py", line 756, in get_objects
qs = self.get_queryset()
File "/home/keo7/.local/lib/python2.7/site-packages/flask_mongorest/resources.py", line 546, in get_queryset
return self.document.objects
AttributeError: type object 'AdductWeights' has no attribute 'objects'
from flask-mongorest.
Are you using AdductWeights
as a document
in your resource? EmbeddedDocument
s can't be used this way, only Document
classes. EmbeddedDoc.objects
indeed doesn't exist.
from flask-mongorest.
These are my resources.
class PositiveResource(Resource):
document = d.Positive
class NegativeResource(Resource):
document = d.Negative
class AdductWeightsResource(Resource):
document = d.AdductWeights
related_resources = {
"positive" : PositiveResource,
"negative" : NegativeResource
}
class MetaboliteAdductResource(Resource):
document = d.MetaboliteAdduct
related_resources = {
"adduct_weight" : AdductWeightsResource
}
How else am I supposed to be using them?
from flask-mongorest.
First of all, thanks @KeironO for uncovering all the things that should be covered by the documentation. Appreciate your inquiries :)
Change "adduct_weight"
to "adduct_weights"
in related_resources
.
Edit: Removed previous invalid answer.
Note to self: typo in the field name in related_resources
should raise a more obvious error.
from flask-mongorest.
@wojcikstefan not a problem, once I get my head around it I'll probably go about creating a simple-CMS to demonstrate said functionality simplistically for others.
Even when I change the "related_resources" field name, the same error is given.
Documents:
class Positive(EmbeddedDocument):
count = IntField()
peaks = StringField() # Temporary
class Negative(EmbeddedDocument):
count = IntField()
peaks = StringField() # Temporary
class AdductWeights(EmbeddedDocument):
negative = EmbeddedDocumentField(Negative)
positive = EmbeddedDocumentField(Positive)
neutral = FloatField()
class MetaboliteAdduct(Document):
meta = {"collection" : "metabolites"}
name = StringField()
adduct_weights = EmbeddedDocumentField(AdductWeights)
Resources
class PositiveResource(Resource):
document = d.Positive
class NegativeResource(Resource):
document = d.Negative
class AdductWeightsResource(Resource):
document = d.AdductWeights
related_resources = {
"positive" : PositiveResource,
"negative" : NegativeResource
}
class MetaboliteAdductResource(Resource):
document = d.MetaboliteAdduct
related_resources = {
"adduct_weights" : AdductWeightsResource
}
from flask-mongorest.
Update: I managed to fix that issue, I'm just struggling to get the operators to work.
Documents:
class PositiveAdduct(EmbeddedDocument):
count = IntField()
peaks = StringField()
class NegativeAdduct(EmbeddedDocument):
count = IntField()
peaks = StringField()
class AdductWeights(EmbeddedDocument):
neutral = FloatField()
positive = EmbeddedDocumentField(PositiveAdduct)
negative = EmbeddedDocumentField(NegativeAdduct)
class MetaboliteAdduct(DynamicDocument):
meta = {"collection" : "metabolites"}
name = StringField()
adduct_weights = EmbeddedDocumentField(AdductWeights)
Resources:
class NegativeAdductResource(Resource):
document = d.NegativeAdduct
filters = {
"count" : [ops.Gt]
}
class PositiveAdductResource(Resource):
document = d.PositiveAdduct
class AdductWeightsResource(Resource):
document = d.AdductWeights
related_resources = {
"positive" : PositiveAdductResource,
"negative" : NegativeAdductResource
}
class MetaboliteAdductResource(Resource):
document = d.MetaboliteAdduct
filters = {
"name" : [ops.Exact]
}
related_resources = {
"adduct_weights" : AdductWeightsResource
}
When I attempt to query the API using the following request:
adducts/?adduct_weights_negative_count__gt=0
Nothing seems to happen!
from flask-mongorest.
@KeironO remove the filters from the sub-resources and on the main MetaboliteAdductResource
add:
filters = {
'adduct_weights__positive__count': [ops.Gt],
'adduct_weights__negative__count': [ops.Gt]
}
Then, you can query it by doing e.g. GET /metabolite/?adduct_weights__negative__count__gt=2
. Note that subfields are separated from fields the same way as operators - by double underscores.
from flask-mongorest.
Haha, no problem mate. Thanks for pointing out some parts where Flask-MongoRest is not intuitive nor documented well. It's very helpful to see the problems through a new adopter's eyes!
I think we can close this issue now. I renamed it so that it's easier to find by others.
from flask-mongorest.
Related Issues (20)
- Default implementation of handle_serialization_error should raise
- Dealing with embedded documents. HOT 24
- Writing an operator, taking the index of a ListField into account. HOT 1
- Using a projection on a dataquery HOT 3
- How to use JWT Decorator
- How to return PyMongo cursor?
- Filtering list issue
- Limit field in MapfField
- Exclude field HOT 9
- Error: A ReferenceField only accepts DBRef, ObjectId or documents
- Saving Reference field along with object in POST request
- pip don't install package
- has_add_permission() cannot prevent object creation HOT 1
- pip hasn't been updated since 2012 HOT 2
- Allow for custom Encoder class HOT 1
- Support lazy initialization / use init_app HOT 1
- Python 3 incompatible syntax on views.py HOT 4
- example app can't run success HOT 8
- Compatibility with mongoengine[original] HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-mongorest.