User-generated fields in Django -


i'm building djano application displays set of images, , form each image recording specific image characteristics. user initializes "project", specify set of images displayed assessment. @ project initialization, i'd give user ability add custom boolean fields (i.e. set of checkboxes), can't figure out how build database models.

for example, user might initialize my_project image_a.png, image_b.png , image_c.png assessment. default form they'll each image lets them choose between pass, fail , unknown. might wish add custom fields "poorly cropped", "over-exposed" or "blurry" (the idea being image global pass, small failures, specific context of image set, still recorded).

generally, i'm trying come way model user-generated fields in django.

if correctly understand, don't need dynamic model fields, instead can add model, contains specific attributes image in project, like:

class image(models.model):     name = models.charfield()     img = models.imagefield()  class projectimage(models.model):     image = models.foreignkey('image')     project = models.foreignkey('project')     flag = models.charfield(choices=pass_fail_unknown)  class projectimagetag(models.model):     project_image = models.foreignkey(projectimage)     value = models.charfield()  class project(models.model):     images = models.manytomanyfield('image', through=projectimage) 

also, can store such tags in json field or postgres hstore field instead of separate table.

edit

variation predefined keys:

class projectimage(models.model):     image = models.foreignkey('image')     project = models.foreignkey('project')     flag = models.charfield(choices=pass_fail_unknown)  class image(models.model):     name = models.charfield()     img = models.imagefield()  class project(models.model):     images = models.manytomanyfield('image', through=projectimage)  class projectimageparams(models.model):     project_image = models.foreignkey(projectimage, related_name='params')     key = models.charfield()     value = models.booleanfield() 

params of image may obtained projectimage().params.all(). , yes, django-eav may option.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -