Skip to content

Instantly share code, notes, and snippets.

@gsiegman
Created November 20, 2012 05:35
Show Gist options
  • Save gsiegman/4116230 to your computer and use it in GitHub Desktop.
Save gsiegman/4116230 to your computer and use it in GitHub Desktop.
Why?
# models
class Track(models.Model):
id = models.IntegerField(primary_key=True)
recording = models.IntegerField()
tracklist = models.ForeignKey(Tracklist, db_column="tracklist", related_name="tracks")
position = models.IntegerField()
name = models.CharField(max_length=255, unique=True)
artist_credit = models.ForeignKey(
ArtistCredit,
null=True,
blank=True,
db_column="artist_credit",
related_name="tracks")
length = models.IntegerField(null=True, blank=True)
edits_pending = models.IntegerField()
last_updated = models.DateTimeField(null=True, blank=True)
class Meta:
db_table = "s_track"
class ArtistCredit(models.Model):
artist_credit = models.IntegerField(primary_key=True)
position = models.SmallIntegerField()
artist = models.ForeignKey(Artist, db_column="artist", related_name="credits")
name = models.CharField(max_length=255)
join_phrase = models.TextField(blank=True)
class Meta:
db_table = "s_artist_credit_name"
# code
tracks = Track.objects.all()[0:10]
for track in tracks:
print track.artist_credit.name
# error
MultipleObjectsReturned: get() returned more than one ArtistCredit -- it returned 2! Lookup parameters were {'artist_credit__exact': 988330}
# db screenshot links
http://cl.ly/L16p
http://cl.ly/L0iC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment