1👍
You don’t put the “B” in a string. It should be:
class A(db.Model):
b = db.ReferenceProperty(B)
class B(db.Model):
pass
1👍
Using ndb
class A(ndb.Model):
b = ndb.KeyProperty('B')
class B(ndb.Model):
pass
To find all instances of A, that refer to B
A.query(A.b == somekey_for_b)
This could be a method of B which is the equivalent of a db collection set but is not automagical and doesn’t have the issue of collection set name clashes
Alternately if you must stick with db
then either change the order of class definition, or just use db.Model
as the kind for the reference property definition rather than the actual class. It will still work, it just won’t check the specific Kind at update time.
You can validate that the correct kind is supplied by supplying your own validate method
- [Answered ]-How to fix "ImportError: No module named …" error
- [Answered ]-Filter Django queryset
- [Answered ]-Using ElasticSearch as Database/Storage with Django
- [Answered ]-Show initial value for FileField in django-template
- [Answered ]-Django can't download file via admin
Source:stackexchange.com