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!