Skip to content

Commit

Permalink
feat: added parent field for table
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Romaniuk committed Sep 24, 2021
1 parent 1783e75 commit 7881006
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
18 changes: 18 additions & 0 deletions core/migrations/0043_table_parent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.3 on 2021-09-24 10:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0042_alter_url_author"),
]

operations = [
migrations.AddField(
model_name="table",
name="parent",
field=models.CharField(blank=True, max_length=120, null=True),
),
]
1 change: 1 addition & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class Table(models.Model):
heading = models.CharField(max_length=31, blank=True, null=True)
array_tables = models.ManyToManyField("self", blank=True)
column_headings = models.JSONField(default=dict, encoder=DjangoJSONEncoder, blank=True, null=True)
parent = models.CharField(max_length=120, blank=True, null=True)

def __str__(self):
return f"{self.__class__.__name__} {self.id}"
Expand Down
4 changes: 2 additions & 2 deletions core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class ArrayTablesSerializer(serializers.ModelSerializer):
class Meta:
model = Table
fields = ("id", "name", "include", "heading")
fields = ("id", "name", "include", "heading", "parent")


class DataFileSerializer(serializers.ModelSerializer):
Expand All @@ -27,7 +27,7 @@ class TablesSerializer(serializers.ModelSerializer):
class Meta:
model = Table
read_only_fields = ("array_tables",)
fields = ("id", "name", "split", "array_tables", "include", "heading")
fields = ("id", "name", "split", "array_tables", "include", "heading", "parent")


class FlattenSerializer(serializers.ModelSerializer):
Expand Down
4 changes: 3 additions & 1 deletion core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ def _split_table(self, table, analyzed_tables, datasource, child_tables):
},
)
continue
child_table = Table.objects.create(name=child_table_key)
child_table = Table.objects.create(
name=child_table_key, parent=analyzed_tables[child_table_key].parent.name
)
table.array_tables.add(child_table)
preview_path = f"{datasource_dir}/{child_table_key}_combined.csv"
store_preview_csv(COLUMNS, PREVIEW_ROWS, analyzed_tables[child_table_key], preview_path)
Expand Down

0 comments on commit 7881006

Please sign in to comment.