Monday, June 26, 2017

Re: Retrieve field values from ManyToMany field in model

On Sunday 25 June 2017 15:08:25 Mark Phillips wrote:

> I have this class

>

> class DocumentMetaData(models.Model):

> document = models.ManyToManyField(Document)

> metadata = models.ManyToManyField(MetaData)

> metadatavalue = models.ManyToManyField(MetaDataValue)

 

That design is wrong. This is the design you want:

 

class DocumentMetaData(models.Model):

name = models.CharField()

value = models.TextField()

 

class Document(models.Model):

title = models.CharField()

metadata = models.ManyToManyField(DocumentMetaData)

 

This design allows many metadata with name and value to be linked to a each document. I'm not entirely sure how to describe what your data design accomplishes and I'm guessing you can't either or it doesn't accomplish what you think it should.

--

Melvyn Sopacua

No comments:

Post a Comment