Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. # query to get producer and pharmaceutical company of product
  2. # takes three arguments: first authnr of bloodproduct, second name of company, third name of producer
  3. # default is none -> gets all
  4. # argument as string: 'Name' or as like: '%Name%'
  5. def query_comp_prod_product(authnr=None, company=None, producer=None):
  6. queryset = session.query(Medicinal_Product, Pharma_Company, Producer).\
  7. filter(Medicinal_Product.id == Producer.medicinal_product_id).\
  8. filter(Pharma_Company.id == Producer.pharma_comp_id).\
  9. filter(Pharma_Company.id == Medicinal_Product.pharma_comp_id)
  10.  
  11. # only add the filter if it was passed in
  12. if authnr:
  13. queryset = queryset.filter(
  14. Medicinal_Product.authnr.like(authnr)
  15. )
  16. if company:
  17. queryset = queryset.filter(
  18. Pharma_Company.name.like(company)
  19. )
  20. if producer:
  21. queryset = queryset.filter(
  22. Producer.name.like(producer)
  23. )
  24.  
  25. # printing statement of query
  26. for mp, c, p in queryset.all():
  27. print("Medicinal Product: %s; Name: %s" % (mp.authnr, mp.name))
  28. print("Pharmaceutical Company: %s" % c.name)
  29. print("Producer: %s" % p.name)
  30. print("-------------------------")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement