Saturday, May 11, 2013

Re: Trying to figure out ManyToManyField on a legacy database

Thanks Kevin, that did the trick.

This is going to be an interesting project. There are 3 different
database types with DJ's song info involved. Each DJ has their private
database.

Can I have different models, and have a way to link the different DJ's
databases to the correct model for their database type?

Brian

On Sat, 2013-05-11 at 16:37 -0700, kevin wrote:
> Hi Brian,
>
> It seems like you don't really have an Many To Many relationship
> between your "Song" and "Played" objects. I can see how you would
> have multiple plays for one song, but considering that the Played
> model has a track_id, would you ever have multiple songs for a single
> Play? It appears that "track_id" is intended to be a foreign key
> into the Song table, so maybe you could consider using a ForeignKey
> field to refer to your Song through your Played object. Django will
> automatically create 2-way references so you can get to your played
> objects from your song object::
>
>
> class Played(models.Model):
> played_id = models.IntegerField(primary_key=True)
> track = models.ForeignKey('Song')
> date_played = models.DateTimeField()
> played_by = models.CharField(max_length=255L)
> played_by_me = models.IntegerField()
> class Meta:
> db_table = 'played'
>
>
>
> class Song(models.Model):
>
> id = models.IntegerField(primary_key=True)
> title = models.CharField(max_length=255L, blank=True)
> class Meta:
> db_table = 'song'
>
>
> Then, you should be able to get all of the Plays for a particular
> song::
>
>
>
>
> s = Song.objects.get(id=1229)
> s.title # should be OK still
> s.played_set.all() # should be a list of plays.



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate