Use "dynamic" schemas defined in the DB

81 views
Skip to first unread message

honi

unread,
Oct 30, 2014, 9:33:14 AM10/30/14
to django...@googlegroups.com
With reload_schema, could it be possible to define the schemas in the DB (in another model)?

For example:

class Datasheet(models.Model):
    schema
= models.TextField()


class Product(models.Model):
    datasheet
= models.ForeignKey(Datasheet)
    specs
= hstore.DictionaryField()


class ProductForm(forms.ModelForm):
   
class Meta:
        model
= Product
        fields
= ['specs']

   
def __init__(self, datasheet, *args, **kwargs):
       
super(ProductForm, self).__init__(*args, **kwargs)
       
self.datasheet = datasheet
        specs
= Product._meta.get_field('specs')
        specs
.reload_schema(datasheet.schema)

   
def save(commit=True):
        obj
= super(ProductForm, self).save(commit=False)
        obj
.datasheet = self.datasheet
       
if commit:
            obj
.save()
       
return obj

I'm not sure if this can have unwanted side effects. Also, the schema reloading bit would need to happen anytime you want to use the Product model.

Any ideas / suggestions are welcomed.
Thanks!

David Burke

unread,
Nov 28, 2014, 4:53:57 PM11/28/14
to django...@googlegroups.com
I'm interested in this idea. Did you make any progress? I'd love to make a graphical interface to allow users to add new fields to the schema. I may work on it as a pull request or add-on project.

matthieu bellon

unread,
Mar 24, 2015, 3:59:57 AM3/24/15
to django...@googlegroups.com
Also interested in such scenario. Do you have a feedback on this Honi ? David ?

matthieu

unread,
Mar 24, 2015, 4:15:38 AM3/24/15
to django...@googlegroups.com
I would say that this is the very point of reload_schema. It exists for such scenario.
Would be great to hear a maintainer on this.

nemesis

unread,
Mar 24, 2015, 6:07:26 AM3/24/15
to django...@googlegroups.com
Hi,

I think it would be possilbe.

Don't know about the consequences, but if anyone finds it useful for his project and can explore that possibility it will surely be a matter of interest to know what happens and if it play wells.

Federico

matthieu

unread,
Mar 24, 2015, 8:54:00 AM3/24/15
to django...@googlegroups.com
If we can debug our other issue (https://groups.google.com/forum/#!topic/django-hstore/s8e_QD3KaLU) we will try.

First consequence that come to my mind is performance, each read/write goes through more logic.
Reply all
Reply to author
Forward
0 new messages