Hi all,

I'm trying to configure these two classes so the song class returns the 
contents of the file dictionary as well but am having issues figuring this 
out. 
Here is what I have so far. If you have any suggestions on how I can get 
Song.as_dictionary to return something like this:

> {
>
>     "id": 1,
>
>     "file": {
>
>         "id": 7,
>
>         "name": "Shady_Grove.mp3"
>
>     }
>
> }
>
>  
This is what I have so far

> class Song(Base):
>
>     """ The Song model:
>
>     This should have an integer id column,
>
>     a column specifying a one-to-one relationship with a File. """
>
>     __tablename__ = "songs"
>
>     id = Column(Integer, Sequence('song_id_sequence'), primary_key=True)
>
>     info = relationship("File", uselist=False, backref="songs")
>
>
>>     def as_dictionary(self):
>
>         song = {
>
>             "id": self.id,
>
>             "info": self.info }
>
>         # need to add file info in here
>
>         return song
>
>
>> class File(Base):
>
>     """ The File model: This should have an integer id column
>
>     a string column for the file name
>
>     and the backref from the one-to-one relationship with the Song."""
>
>     __tablename__ = "files"
>
>     id = Column(Integer, Sequence('file_id_sequence'), primary_key=True)
>
>     name = String(1024)
>
>     song_id = Column(Integer, ForeignKey('songs.id'))
>
>
>>     def as_dictionary(self):
>
>         file = {
>
>             "id": self.id,
>
>             "name": self.name }
>
>         return file
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to