A
A
AntonyPy2020-12-04 20:30:16
Flask
AntonyPy, 2020-12-04 20:30:16

How to write all data of a Flask model to a field of another model?

There is a Movie model with id, rating, comment and name fields.

class Movie(Base):
    __tablename__ = "movie's"
    id = Column(Integer, primary_key = True)
    name = Column(String(255))
    rating = Column(Float)
    comment = Column(sqlalchemy_jsonfield.JSONField(
            enforce_string=True,
            enforce_unicode=False,
            json=ujson,  
        ))


As you can see, the model has a comment json field, in which I want to write all the field data from another Comment model when they are filled:

class Comment(Base):
    __tablename__ = "comments"
    id = Column(Integer, primary_key = True)
    commentator_name = Column(String(50)
    /and another field/


How to do it?

Important : I need to have a separate Comment model, this is required by my task, so the answer in the style of "transfer these fields to the Movie model" is not welcome

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dooMoob, 2020-12-04
@dooMoob

Nafiga and most importantly why? Relational databases are not called relational for nothing, I advise you to read about their essence

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question