I used to have the task of a more specific version of this question, but I could not formulate my question. On reflection, I questioned that my chosen solution was the right one for the problem, so this time I will explain the problem and ask: a) I am on the right path and b) if there is a path around my current brick wall.
I am currently creating a web interface that allows me to test an existing database (a small number) of users. Having an analogy with the docs, I have models that look something like this:
class Musician(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
dob = models.DateField()
class Album(models.Model):
artist = models.ForeignKey(Musician)
name = models.CharField(max_length=100)
class Instrument(models.Model):
artist = models.ForeignKey(Musician)
name = models.CharField(max_length=100)
() , ForeignKey, OneToOneFields. , , . , , , . 2- ( ) .
, ~ 5000 20 .
, . , , ( ), , .
, , :
class UserDataSets(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=100)
description = models.CharField(max_length=64)
results = models.ManyToManyField(Musician, through='UserData')
class UserData(models.Model):
artist = models.ForeignKey(Musician)
dataset = models.ForeignKey(UserDataSets)
score = models.IntegerField()
class Meta:
unique_together = (("artist", "dataset"),)
, , 1 1 "". , .
, . - :
artist = Musician.objects.get(pk=1)
dataset = UserDataSets.objects.get(pk=5)
print artist.userdata_set.get(dataset=dataset.pk)
, , single. , UserData :
artists = Musician.objects.all().order_by(userdata__score)
. , "" (, > 5 1 2 2).
, ?