django database models with one field common -


i struggling define django models can achieve following functionality per picture below:

solution required

basically,

i want able create new projects (so, create model: class projectlist).

i want assign generic list of stages each project create model: class stagelist. stage list contains list of stages names same each project.

stages should contain integer values average values of area fields.

so, want create list of areas , create model: class arealist.

arealist may different every project.

the important think end user wants see is:

a value of stage 1 (which average) project 1. stage 1 average of example area 1, area 2 in project 1.

stage 2 avg of area 1, area 2 in project 2

etc.

i thought doing relation arealist below:

area_num = models.foreignkey(stagelist, related_name='area_items') 

i realized not way because relates specific stage in stage list want have few different area values different stages.

how can ?

what believe you're looking following:

class project(models.model):     pass  class stage(models.model):     pass  class area(models.model):     project = models.foreignkey(project)     stage = models.foreignkey(stage)     value = models.integerfield() 

then stage values you'd like:

from django.db.models import avg project = project.objects.get(...) project_stages = stage.objects.filter(     area_set__project=project ).annotate(     stage_value=avg('area_set__value') ) project_stage in project_stages:     print project_stage.stage_value 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -