Is there any way to simplify this code, because each time putting an instance name to access the class variable is annoying. I am basically forming Kotlin background, we use with to access the properties of the class.
Kotlin eg:
val notification = Notification()
with(notification){
created_at = datetime.datetime.now()
recipient_id = recipient
//etc
}
notification.py
class Notification(CustomerBase, Base):
__tablename__ = "notification"
created_at = Column(DateTime, nullable=True, default=datetime.datetime.now())
recipient_id = Column(Integer, ForeignKey("users.id"), nullable=True)
sender_id = Column(Integer, ForeignKey("users.id"), nullable=True)
data = Column(JSONB, nullable=True)
message = Column(String, nullable=True)
type = Column(String, nullable=True)
activity_id = Column(Integer, nullable=True)
is_read = Column(BOOLEAN, nullable=True, default=False)
sender_info = relationship("User", foreign_keys=[sender_id])
recipient_info = relationship("User", foreign_keys=[recipient_id])
entity_id = Column(Integer, nullable=True)
entity_name = Column(String, nullable=True)
Saving notification to session.
notification = Notification()
notification.created_at = datetime.datetime.now()
notification.recipient_id = recipient
notification.sender_id = activity.created_by
notification.message = add_people_msg(user, added_user, activity)
notification.type = NotificationTypes.PEOPLE.value
notification.customer_id = activity.customer_id
notification.entity_id = activity.id
notification.customer_id = activity.customer_id
notification.activity_id = activity.id
notification.data = activity_data
self.session.add(notification)