Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # query to get producer and pharmaceutical company of product
- # takes three arguments: first authnr of bloodproduct, second name of company, third name of producer
- # default is none -> gets all
- # argument as string: 'Name' or as like: '%Name%'
- def query_comp_prod_product(authnr=None, company=None, producer=None):
- queryset = session.query(Medicinal_Product, Pharma_Company, Producer).\
- filter(Medicinal_Product.id == Producer.medicinal_product_id).\
- filter(Pharma_Company.id == Producer.pharma_comp_id).\
- filter(Pharma_Company.id == Medicinal_Product.pharma_comp_id)
- # only add the filter if it was passed in
- if authnr:
- queryset = queryset.filter(
- Medicinal_Product.authnr.like(authnr)
- )
- if company:
- queryset = queryset.filter(
- Pharma_Company.name.like(company)
- )
- if producer:
- queryset = queryset.filter(
- Producer.name.like(producer)
- )
- # printing statement of query
- for mp, c, p in queryset.all():
- print("Medicinal Product: %s; Name: %s" % (mp.authnr, mp.name))
- print("Pharmaceutical Company: %s" % c.name)
- print("Producer: %s" % p.name)
- print("-------------------------")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement