Admin Master-Detail: Dynamically filter selections in detail

10 views
Skip to first unread message

Stephan Jaschke

unread,
Feb 11, 2018, 5:43:11 AM2/11/18
to django...@googlegroups.com
Hi all.

I'm trying to implement a customizable import-module for csv-data into
elasticsearch-indices. The use may select a csv-schema with given fields
and create a mapping to arbitary indices. This mapping schould be done
on field level.

So I ended up with following simplified models:

class CSVSchemaField(models.Model):
schema = models.ForeignKey(
'CSVSchema',
related_name'fields'
)
name = models.CharField()

class CSVSchema(models.Model):
name = models.CharField()

class IndexSchemaField(models.Model):
schema = models.ForeignKey(
'IndexSchema',
related_name'fields'
)
name = models.CharField()

class IndexSchema(models.Model):
name = models.CharField()

... and the mapping models ...

class MappingFieldMap(models.Model):
mapping = models.ForeignKey(
'Mapping',
related_name'fields'
)
csv_field = models.ForeignKey(
CSVSchemaField,
)
index_field = models.ForeignKey(
IndexSchemaField,
)

class Mapping(models.Model):
csv_schema = models.ForeignKey(
CSVSchema,
)
index_schema = models.ForeignKey(
IndexSchema
)

For the admin I created a standard-form for the Mapping with
tabular-inlines for the MappingFieldMap. This gave me two select-boxes
on top and a couple of inlines below, each with to select-boxes.

If I change any of the Master-Fields I would like the select-boxes in
the inlines to reflect that change and to show only Fields which are
bound to that specific csv resp. index-schema.

It seems that this should be doable via js and ajax but I've no idea how
this should be done. Any ideas, pointers or hints?

Regards
Stephan

Melvyn Sopacua

unread,
Feb 11, 2018, 8:39:06 AM2/11/18
to django...@googlegroups.com

On zondag 11 februari 2018 11:36:01 CET Stephan Jaschke wrote:

 

> If I change any of the Master-Fields I would like the select-boxes in

> the inlines to reflect that change and to show only Fields which are

> bound to that specific csv resp. index-schema.

>

> It seems that this should be doable via js and ajax but I've no idea how

> this should be done. Any ideas, pointers or hints?

 

All ajax/js done for you in DAL.

--

Melvyn Sopacua

Reply all
Reply to author
Forward
0 new messages