I have a jsonb field in a table having values of the form
from sqlalchemy.dialects.postgresql import JSONB
class Product(db.Model):
__tablename__ = 'tbl_product'
id = db.Column(db.Integer(), primary_key=True)
name = db.Column(JSONB, nullable=False, index=True, unique=True)
slug = db.Column(JSONB, nullable=False, index=True, unique=True)
And I have product names in different languages:
name = {'en': 'Notebook', 'de': 'Notizbuch', ..... }
I want to make search from column name but I don't know in which language it appears, here I can search on specific language:
def get_product_by_name(name, lang):
q = Product.query
q = q.filter(Product.slug[lang].as_string() == slug)
return q.first()
1Q: How can I search without language information? 2Q: Can I order product with language? Somethign like this:
def get_products(lang):
q = Product.query
q = q.order_by(Product.name[lang].asc())
return q.all()