Hi guys,
I'm trying to solve this without raw SQL, from the past 4/5 days.
I've been also researching a lot to understand more complex queries in
django so I would realy appreciate your help since I plan to continue
using django in my projects.
I have a:
class VoteContext(models.Model):
name = models.CharField(max_length = 15, unique = True)
class Vote(models.Model):
thing = models.ForeignKey(Thing, null = False)
context = models.ForeignKey(VoteContext, null = False)
user = models.ForeignKey(User, null = False)
vote = models.DecimalField(default = 0, max_digits = 3,
decimal_places = 1, null = False)
class Meta:
unique_together = ("thing", "user", "context")
Something like this in the database: (I will put names instead of IDs
for easier understanding)
mydatabase_votecontext
(id, name)
(1, Flavour)
(2, Smell)
(3, Usability)
(4, Size)
mydatabase_vote
(id, thing, context, user, vote)
(1, Potatoes, Flavour, Me, 2.0)
(2, Potatoes, Smell, Me, 4.3)
(3, Potatoes, Usability, Me, 4.0)
(4, Carrots, Flavor, Me, 3.0)
(5, Cars, Smell, Me, 4.2)
(6, Cars, Usability, Me, 4.9)
I would like to make a query for -> one specific "thing"<-, like,
Carrots, being the result:
(Carrots, Flavour, 2.0)
(Carrots, Smell, 0.0)
(Carrots, Usability, 0.0)
(Carrots, Size, 0.0)
or
(Carrots, Flavour, 2.0)
(Carrots, Smell, null)
(Carrots, Usability, null)
(Carrots, Size, null)