django-dynamic-models icon indicating copy to clipboard operation
django-dynamic-models copied to clipboard

Array Field is not supported

Open yvsssantosh opened this issue 5 years ago • 7 comments

Requesting feature to support type ArrayField to allow the user to store data in an array.

yvsssantosh avatar Aug 19 '19 17:08 yvsssantosh

@rvinzent Kindly think about this and let me know if this can be achieved. I'll try to help if possible

yvsssantosh avatar Aug 19 '19 17:08 yvsssantosh

@yvsssantosh apologies for the delayed response. This sounds like a nice addition to the project :smile: . It should come with some checking to make sure array fields are supported by the database.

rvinzent avatar Oct 06 '19 23:10 rvinzent

I think best way to implement this without building a complex logic to check whether database supports array fields or not will be to do it the way Django does.

  1. Firstly, the data_type argument should accept a special class_object something like
from dynamic_models import fields as dynamic_fields
color_field_schema = FieldSchema.objects.create(name='color', data_type=dynamic_fields.CharField(max_length=200)')
  1. Then, make a module specific to supported databases and put the ArrayField class there. Django example would be from django.contrib.postgres.fields import ArrayField
from dynamic_models.postgres.fields import ArrayField

This way, it's explicit and devs can make their own decision.

I know it's already implemented and will be release in 0.2.0 but I just wanted to give my suggestion.

Thanks for this lib

arpitremarkable avatar Apr 24 '20 10:04 arpitremarkable

@arpitremarkable

I know it's already implemented and will be release in 0.2.0

Where can you see that it is already implemented and that there is a version 0.2.0?

dankgen-tobias avatar May 06 '20 10:05 dankgen-tobias

@dankgen-tobias I assumed it's done since author claimed somewhere that 0.2.0 will be released soon. And this is marked 0.2.0 candidate.

arpitremarkable avatar May 06 '20 12:05 arpitremarkable

@arpitremarkable @dankgen-tobias 0.2.0 was released today and this feature unfortunately did not make it in. 0.2.0 is a big change to the API, but I wanted to limit the addition of new features in order to not delay the release any further.

Increased data type support is absolutely on the radar, and PRs are always appreciated!

rvinzent avatar May 17 '20 10:05 rvinzent

  1. Firstly, the data_type argument should accept a special class_object something like
from dynamic_models import fields as dynamic_fields
color_field_schema = FieldSchema.objects.create(name='color', data_type=dynamic_fields.CharField(max_length=200)')

@arpitremarkable The challenge with accepting Field instances as arguments is it's not entirely clear how to store that information in the database so it can be reconstructed later. It could be something like classname and kwargs fields, but kwargs would have to only contain serializable data types for values.

I like the idea though and it should be possible to implement and allow a lot more flexibility to the kinds of fields that can be used.

rvinzent avatar Nov 10 '20 20:11 rvinzent