A DocumentMetaData instance may be associated with multiple documents
and multiple metadata according to your model, so your question is
ambiguous.
If you want a particular DocumentMetaData to only refer to a single
document and a single metadata then change the ManyToManyField for a
ForeignKey
If you do that then you can do self.document.title and
self.metadata.name to access those fields.
On 6/25/17, Mark Phillips <ma...@phillipsmarketing.biz> wrote:
> I have this class
>
> class DocumentMetaData(models.Model):
> document = models.ManyToManyField(Document)
> metadata = models.ManyToManyField(MetaData)
> metadatavalue = models.ManyToManyField(MetaDataValue)
>
> def __str__(self):
> return "%s - %s" % (self.document, self.metadata)
>
> The Document class has a field called 'title' and the Metadata class has a
> field called 'name'. How do I accesses these two fields from the class
> DocumentMetaData so the string output is something like <document.title> -
> <
> metadata.name>?
>
> Thanks!
>
> Mark
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAEqej2NCVAp07CvESrUnR7k61UG4b0_q5OcaemfOrh%2B77mnTdQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei0k-kV42aK%2BcT0%2By5jLGtaZOG3U2YPGT35j1nixJFxn9g%40mail.gmail.com.
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
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3017602.KsclWe1iua%40devstation.