I am creating a mindmap visio-like editor website using d3js and a bunch of custom javascript. Rather than the schema/stencils being populated by static JSON files, I wanted to create an administration area to edit the schema without requiring JSON kung-fu skills and serve the dynamically generated JSON to my javascript app on the fly.
I have 2 models that I am trying to figure out the best way to create a relationship between. class EditorVocab(models.Model): VOCAB_TYPES = ( ('string', 'String'), ('textarea', 'Text Box'), ('list', 'List of values'), ('list-identifier', 'Open Vocabulary/Dictionary'), ('object_ref', 'Object Reference'), ) vocab_name = models.CharField(max_length=255, unique=False, blank=False, null=False) label = models.CharField(max_length=255, unique=False, blank=False, null=False) help_text = models.CharField(max_length=255, unique=False, blank=True, null=True) default_value = JSONField(default={}, blank=True, db_index=True) vocab_type = models.CharField(max_length=255, choices=VOCAB_TYPES, unique=False, blank=False, null=False) class Meta: managed = True db_table = 'editor_vocabularies' def __str__(self): return '%s (%s)' % (self.label, self.vocab_type) class EditorStencil(models.Model): stencil_type = models.CharField(max_length=32, unique=True) stencil_name = models.CharField(max_length=128, unique=False) stencil_icon = models.FileField(upload_to='stencils') schema = models.ForeignKey(EditorSchema, on_delete=models.CASCADE) vocab = models.ManyToManyField(EditorVocab, related_name="vocabs") vocab_requirement = models.ManyToManyField(EditorVocab, related_name="required_vocabs", blank=True) class Meta: managed = True db_table = 'editor_stencil' def __str__(self): return '%s (%s)' % (self.stencil_name, self.stencil_name) I am using Postgres with the jsoneditor integrated into the Django Admin area and it works well. What I would like to have is a One-to-Many relationship from EditorStencils -> EditorVocab and be able to select/edit/add which "vocabs" are apart of a stencil as well as required. This works with ManyToManyFields but a vocab needs to belong to a stencil. The way it is now, it could potentially belong to multiple stencils (which I do not want). Thanks in advance! -- 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+unsubscr...@googlegroups.com. To post to this group, send email to django-users@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/55ae3904-85f7-44f0-a288-eaf6a97bdc98%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.