Filter choices in form fields based on selected items in fields of the same form django -


i trying create multiple configurations game of type.

updated:

class gametype(models.model):     tag = model.charfield()     name = model.charfield()  class gameconfig(models.model):     tag = model.charfield()     game_type = model.foreignkey('gametype')     text_settings = model.manytomanyfield('gametextsettings')     levels_settings = model.manytomanyfield('gamelevelsettings')  class gametextsettings(models.model):     tag = model.charfield()     texts = arrayfield(models.charfield(max_length=maxlengthtext), default=list, blank=true)  class gamelevelsettings(models.model):     tag = model.charfield()     duration = models.integerfield() 

it nice if, when creating new configuration, can force user first input tag , select type. when selects type want give him options either create new text_settings/level_settings or use text_settings/level_settings associated game_configuration same type.

i think db model wrong have little experience dbs. not want link gamelevelsettings or textsettings directly gametype since should linked gameconfiguration, not know how achieve 'sorting' when presenting user choices.

what suggest?

thank you

edit2: struggle creating views implement logic. have no idea how link views in such way or how filter modelchoicefields choices based on values extracted same form.

extra info:

scenarios: want allow user build multiple gameconfiguration specific gametype. gameconfigurations has array of gamelevelsettings , single textssettings. want make each individual gamelevelsettings , textssettings reusable when user creates new gameconfiguration have same levels different texts can reuse defined gamelevelsettings.

how image should work

  1. the user opens page new gameconfiguration create form (duuh :d )

  2. on form user can select(or create) gametype , input tag new gameconfiguration

  3. once user selects gametype user presented options other fields (textssettings , array of gamelevelsettings) or has ability create new objects . values fields have been pre-filtered objects, associated other (previously created) gameconfigurations same gametype, displayed.

concrete scenario:

  1. i have 3 gametypes defined - blue, red, green, , have created gameconfigurations of them default values.

  2. now want create gameconfiguration gametype blue.

  3. so open create view , input tag "dark blue" , select gametype "blue" dropdown.

  4. once select gametype of values in other fields filtered show objects associated previous default blue gameconfiguration , non of objects associated red/green gameconfigurations shown - easier user not mess , configure blue gametype red textssettings

hope helps.

cheers

django-smart-selects can using fks , rendering jquery scripts fields filter based on other selections in form.

from docs:

if have following model:

class continent(models.model):         name = models.charfield(max_length=255)  class country(models.model):         continent = models.foreignkey(continent)         name = models.charfield(max_length=255)  class location(models.model):     continent = models.foreignkey(continent)     country = models.foreignkey(country)     area = models.foreignkey(area)     city = models.charfield(max_length=50)     street = models.charfield(max_length=100) 

and want if select continent countries available located on continent , same areas can following:

from smart_selects.db_fields import chainedforeignkey   class location(models.model)     continent = models.foreignkey(continent)     country = chainedforeignkey(         country,          chained_field="continent",         chained_model_field="continent",          show_all=false,          auto_choose=true     )     area = chainedforeignkey(area, chained_field="country", chained_model_field="country")     city = models.charfield(max_length=50)     street = models.charfield(max_length=100) 

if you'd see in action page made awhile back, check out thermaline's beercalc , select fields column @ left.

one thing know can use form_fields smart-selects on existing models filter fk selection. in case, had existing model producttype material model has fk to. in sizing form, when selects producttype material selections filtered accordingly.

from smart_selects.form_fields import chainedmodelchoicefield  # arguments = chainedmodelchoicefield(app,model,to_field,modle_field,auto_select=false,show_all=false)  class sizingform(forms.modelform):     material = chainedmodelchoicefield('tubes', 'material', 'product_type', 'product_type', false, false) 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -