I have two models:
# MetaData
class MetaData(models.Model):
metadata_id = models.AutoField(primary_key = True)
name = models.CharField('metadata name', max_length=200, unique=True)
description = models.TextField('description')
def __str__(self):
# MetaData Value
class MetaDataValue(models.Model):
metadata_id = models.ForeignKey(MetaData, on_delete=models.CASCADE,)
value = models.CharField('value', max_length=200, unique=True)
def __str__(self):
return self.value
I want to construct a query set such that I get a dictionary back that looks like this:
{name1: [value1, value2,..], name2:[value3, value4,..]..}
In other words, a dictionary that has the metadata name as the key and the associated values for that name in a list.
I have been playing around with MetaData.objects.all(), but I don't see how to relate the two models and get something close to what I want.
Thanks!
Mark