class PlaceSerializer(serializers.ModelSerializer): location = fields.JSONField() json = fields.JSONField() class Meta: model = Place fields = '__all__'
class ProductSerializer(serializers.ModelSerializer): # pickup_places = PlaceSerializer(many=True) # dropoff_places = PlaceSerializer(many=True) photos = fields.JSONField() bookable_extras = fields.JSONField() json = fields.JSONField() class Meta: model = Activity fields = '__all__'
class NameSerializer(Attestable, serializers.HyperlinkedModelSerializer): url = serializers.HyperlinkedIdentityField(view_name='api:name-detail') identity = serializers.HyperlinkedRelatedField( read_only=True, view_name='api:person-detail') context = serializers.PrimaryKeyRelatedField( queryset=models.NameContext.objects.all()) components = fields.JSONField(required=False) parse = ParseNameField(source='components', required=False, write_only=True) def validate(self, attrs): if 'components' not in attrs: raise serializers.ValidationError( 'Either components or parse is required.') return attrs class Meta: model = models.Name fields = ('identity', 'plain', 'plain_full', 'marked_up', 'familiar', 'sort', 'first', 'last', 'state', 'components', 'parse', 'context', 'attestations', 'url') read_only_fields = ('identity', 'plain', 'plain_full' 'marked_up', 'familiar', 'sort', 'first', 'last')
class OneModuleSerializer(ModuleSerializer): data = fields.JSONField(read_only=True) class Meta: model = models.Module fields = ( 'id', 'path', 'name', 'data', )
class TicketSerializer(serializers.ModelSerializer): log = fields.ListField(child=fields.JSONField()) info = fields.SerializerMethodField(read_only=True) class Meta: model = Ticket fields = ('store', 'created_at', 'updated_at', 'created_by', 'updated_by', 'is_invoiced', 'log', 'info') def get_info(self, obj): return {}
class TaskSerializerV1(dse_serializers.CassandraModelSerializer, BaseCachedSerializerMixin): """ Represents a Business Object API View with support for JSON and map fields. """ user = serializers.CharField(required=False) params = dse_fields.CassandraJSONFieldAsText( required=True, help_text="the set of params used to execute the crawler" " command, this will be saved as Text.") options = dse_fields.CassandraJSONFieldAsText( required=False, help_text="the exactly same content as `options` but saved" " on a way that we can search using solr " "(KeyEncodedMap).", ) more_info = fields.ListField(required=False, allow_null=True, child=TaskMoreInfoSerializer()) differences_from_last_version = fields.JSONField(required=False, allow_null=True) inserted_fields = fields.ListField(required=False, allow_null=True, child=serializers.CharField()) updated_fields = fields.ListField(required=False, allow_null=True, child=serializers.CharField()) deleted_fields = fields.ListField(required=False, allow_null=True, child=serializers.CharField()) changed_fields = fields.ListField(required=False, allow_null=True, child=serializers.CharField()) def create(self, validated_data): request = self.context.get("request", None) if request: self.validated_data["user"] = str(request.user.id) return super(TaskSerializerV1, self).create(validated_data) class Meta: model = Task fields = ( "task_id", "user", "created_at", "updated_at", "is_deleted", "status", "kind", "params", "times_performed", "type", "options", "more_info", "differences_from_last_version", "inserted_fields", "updated_fields", "deleted_fields", "changed_fields", "logging_task", ) read_only_fields = ( "created_at", "updated_at", "is_deleted", "status", "times_performed", "type", "params_map", "options_map", "differences_from_last_version", "inserted_fields", "updated_fields", "deleted_fields", "changed_fields", "logging_task", ) extra_kwargs = { "task_id": { "help_text": "the task id that is the unique partition key." }, "user": { "help_text": "The user that asked for the task, if it is an " "ondemand task." }, "created_at": { "help_text": "the date of the creation of the task." }, "updated_at": { "help_text": "the date that we last updated the task." }, "is_deleted": { "help_text": "controls if the data is deleted." }, "status": { "help_text": """ represents the actual status of the task, could be: - 0 (Created) - 1 (Queued) - 2 (In Progress) - 3 (Finished) - 4 (Faulty) - 5 (Unknown) """, "default": STATUS_CREATED, }, "kind": { "help_text": "the name of the crawler that will execute the " "task." }, "times_performed": { "help_text": "keep track on how many times the task was run." }, "type": { "help_text": "the type of the task, could be OnDemand(1) or " "Batch(2)", "default": ON_DEMAND_TASK, }, "more_info": { "help_text": "more info about the task, for example, something" "about the maintenance state" }, }
class Meta: param_fields = ( ('app_id', fields.CharField()), ('test', fields.JSONField()), ) path = "(?P<app_id>[0-9a-zA-Z]+)/testre"
class DummyJSONSerializer(serializers.Serializer): json_field = fields.JSONField()
class VendorSerializer(serializers.ModelSerializer): json = fields.JSONField() class Meta: model = Vendor fields = '__all__'