Open JDGiacomantonio-98 opened 3 years ago
Thank you very much for you help Jacopo, it is a useful suggestion to make the code more readable and lighter. Once again I appreciate the length to which you go to provide help and explanation to us students. Best regards,
Gabriele Chelini
Il dom 29 nov 2020, 00:03 J. Di Giacomantonio notifications@github.com ha scritto:
Hi @Gabriele-C https://github.com/Gabriele-C , i am reviewing your code trying to help you solving the many-to-many relationship problem you have. Anyway, this is not about that but about this comment you left here:
https://github.com/Gabriele-C/Website1127/blob/2e15112cd5be536826e7214e7cf314ff593f7493/model.py#L29
To do what you are asking for (and should always aim to achieve) i would suggest you to create a "parent class" only used by the SQLAlchemy mapped models only to inherit from the common stuffs (attributes and methods) they all have in common. In this way you will not duplicate unnecessary code and leverage the extremely useful concept of object inheritance of the Object Oriented Programming Paradigm. Therefore i would do something similar to this :
class BaseClass: vegan = db.Column(db.Boolean, nullable=False) lactose_free = db.Column(db.Boolean, nullable=False) gluten_free = db.Column(db.Boolean, nullable=False)
class Recipe(db.Models, BaseClass): name = db.Column(db.String(50), primary_key=True) preparation = db.Column(db.String(20000), nullable=False)
To review another implementation of this exact same concept, maybe just a little bit more intricated, feel free to review this code section https://github.com/JDGiacomantonio-98/polito-projects.__TeamPicks/blob/2fd38e59c121b9e52c5f5788c9a6ce1bf2640e93/app/dbModels.py#L301 coming from the dbModels.py file of my old IS project work. Hope it clarified! Bye. JD
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Gabriele-C/Website1127/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR5DJO7UNLK7PJKABBUWLFTSSF6SHANCNFSM4UGC3OVA .
Hi @Gabriele-C , i am reviewing your code trying to help you solving the many-to-many relationship problem you have. Anyway, this is not about that but about this comment you left here: https://github.com/Gabriele-C/Website1127/blob/2e15112cd5be536826e7214e7cf314ff593f7493/model.py#L29
To do what you are asking for (and should always aim to achieve) i would suggest you to create a "parent class" only used by the SQLAlchemy mapped models only to inherit from the common stuffs (attributes and methods) they all have in common. In this way you will not duplicate unnecessary code and leverage the extremely useful concept of object inheritance of the Object Oriented Programming Paradigm. Therefore i would do something similar to this :
To review another implementation of this exact same concept, maybe just a little bit more intricate, feel free to review this code section coming from the
dbModels.py
file of my old IS project work. Hope it clarified! Bye. JD