In the following example, should I keep the get_friend method inside my class or should I move it outside because I want to separate data structure from business logic ? What's the best practice ? Don't be biased by the class being small, it's just an example but the class could be much bigger.
from sqlalchemy import Column, Integer, String, Float, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class User(Base):
id = Column("id", Integer, primary_key=True)
friends = relationship("Friends")
def get_friend(self, friend_name):
for friend in self.friends:
if friend.name == friend_name:
return friend
return None