forms - Django override-able abstract field for inlineformset -


intro

hello!!!!! i've looked solution problem - nearest thing i've found far this, , doesn't have full enough answer me.

background

the following contrived example make question clearer.

i interested in using inlineformset_factory in situation each entry in form can correspond different subclasses of same parent model. example, have form model has number of input items:

class form(models.model):     name = models.charfield(max_length=30) 

then, have input model , subclasses:

class input(models.model):     class meta:         abstract = true      form = models.foreignkey(form)     name = models.charfield(max_length=30)  class shortinput(input):     value = models.charfield(max_length=20)  class tweetinput(input):     value = models.charfield(max_length=140)  class binaryinput(input):     value = models.textfield(blank=true) 

essentially, it's form various types of data. it's important shortinput instances take 20 characters of space in backend, , binaryinput instances have huge amount of storage space. note every subclass of input have value field, although may of different lengths/types.

what i'd use inlineformset_factory build form model. looks this:

form = inlineformset_factory(     form,     input,     fk_name='form',     fields=['value'] ) 

the intention here build form can edit values of every input entry in database.

the problem

for inlineformset_factory call, django complains input has no field named value.

the question

i feel should able deal problem because can guarantee every input subclass will have value attribute - need tell django in way. ideal thing i'm looking this:

class input(models.model):     class meta:         abstract = true         guaranteed_subclass_fields = [             'value',         ]     ... 

in other words, way of telling django can expect value field in subclasses.

the next best thing i'm looking other way of specifying django can rely on value field existing.

finally, if none of possible, i'm looking other (potentially hackish) way of passing input class value field inlineformset_factory function - perhaps ignoring error or of sort. (although regardless of how hackish solution is, involve use of inlineformset_factory)

thanks in advance help!


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -