List Info

Thread: more model basics - mny to many's




more model basics - mny to many's
user name
2006-02-14 03:58:02
Hiya.
I am not a web developer, okay, just trying to do a band
website (so
take it easy on me, please ;)
I am having trouble with my models.

I have the following:

class musician(meta.Model):
  .......
class instrument(meta.Model):
  .......
class song(meta.Model):
  ......
class songInstrument(meta.Model):
  song = meta.ForeignKey(song, edit_inline=meta.TABULAR,
core=True)
  instrument = meta.ForeignKey(instrument)
  musician = meta.ForeignKey(musician)
  def __repr__(self):
    return "%s, %s, %s" % (self.get_song(),
self.get_musician(),
self.get_instrument())
  class META:
    admin = meta.Admin()

So each song has many musicians playing many instruments
(ie. Jerry
might have played drums and bass and read Chaucer in a
particular
song). This is great, and when I add a song in the admin
section, I can
add all this detail, but when I look at songInstrument in
admin, there
are no entries??

Can anyone tell me:
a) where have I gone wrong?
b) is there an easier way to set up these (and similar)
models?

thanks, 
and keep up to good work, django ist fun

more model basics - mny to many's
user name
2006-02-14 08:59:47
what do you need the table songInstrument for?
iŽd suggest using a many-to-many relationship ... see
http://www.djangoproject.com/documen
tation/model_api/#many-to-many-relations
hips

class song(meta.Model):
title = ...
duration = ...
instrument = meta.ManyToManyField(instrument)
musician = meta.ManyToManyField(musician)
def __repr__(self):
  return self.title()
class META:
  admin = meta.Admin()

patrick


> 
> Hiya.
> I am not a web developer, okay, just trying to do a
band website (so
> take it easy on me, please ;)
> I am having trouble with my models.
> 
> I have the following:
> 
> class musician(meta.Model):
> .......
> class instrument(meta.Model):
> .......
> class song(meta.Model):
> ......
> class songInstrument(meta.Model):
> song = meta.ForeignKey(song, edit_inline=meta.TABULAR,
core=True)
> instrument = meta.ForeignKey(instrument)
> musician = meta.ForeignKey(musician)
> def __repr__(self):
>   return "%s, %s, %s" % (self.get_song(),
self.get_musician(),
> self.get_instrument())
> class META:
>   admin = meta.Admin()
> 
> So each song has many musicians playing many
instruments (ie. Jerry
> might have played drums and bass and read Chaucer in a
particular
> song). This is great, and when I add a song in the
admin section, I can
> add all this detail, but when I look at songInstrument
in admin, there
> are no entries??
> 
> Can anyone tell me:
> a) where have I gone wrong?
> b) is there an easier way to set up these (and similar)
models?
> 
> thanks, 
> and keep up to good work, django ist fun
> 

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )