Skip to content

Commit

Permalink
Fix tile creates
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jan 8, 2025
1 parent 2d518b3 commit 2532fe2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 29 deletions.

This file was deleted.

5 changes: 1 addition & 4 deletions arches/app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1907,10 +1907,7 @@ class TileModel(models.Model): # Tile

tileid = models.UUIDField(primary_key=True, blank=True)
resourceinstance = models.ForeignKey(
ResourceInstance,
db_column="resourceinstanceid",
on_delete=models.CASCADE,
editable=False,
ResourceInstance, db_column="resourceinstanceid", on_delete=models.CASCADE
)
parenttile = models.ForeignKey(
"self",
Expand Down
14 changes: 13 additions & 1 deletion arches/app/models/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rest_framework import serializers

from arches.app.datatypes.datatypes import DataTypeFactory
from arches.app.models.models import Node, TileModel
from arches.app.models.models import Node, ResourceInstance, TileModel
from arches.app.utils.betterJSONSerializer import JSONSerializer


Expand All @@ -18,6 +18,9 @@

class ArchesTileSerializer(serializers.ModelSerializer):
tileid = serializers.UUIDField(validators=[], required=False)
resourceinstance = serializers.PrimaryKeyRelatedField(
queryset=ResourceInstance.objects.all(), html_cutoff=10
)

def __init__(self, instance=None, data=fields.empty, **kwargs):
super().__init__(instance, data, **kwargs)
Expand Down Expand Up @@ -90,6 +93,13 @@ def validate(self, data):
raise ValidationError({unknown_keys.pop(): "Unexpected field"})
return data

# def create(self, validated_data):
# # TODO: we probably want a queryset method to do one-shot
# # creates with tile data
# blank_tile = super().create(validated_data)
# tile_from_factory = self.get_queryset().get(pk=blank_tile.pk)
# return self.update(tile_from_factory, validated_data)


class ArchesModelSerializer(serializers.ModelSerializer):
legacyid = serializers.CharField(max_length=255, required=False, allow_null=True)
Expand Down Expand Up @@ -162,6 +172,8 @@ def validate(self, data):

def create(self, validated_data):
meta = self.__class__.Meta
# TODO: we probably want a queryset method to do one-shot
# creates with tile data
instance_without_tile_data = super().create(validated_data)
instance_from_factory = meta.model.as_model(
graph_slug=self.__class__.Meta.graph_slug,
Expand Down

0 comments on commit 2532fe2

Please sign in to comment.