foreign key within a manytomany within a model in admin

12 views
Skip to first unread message

MikeKJ

unread,
Nov 7, 2013, 8:40:57 AM11/7/13
to django...@googlegroups.com
Sorry didnt know how else to describe what I am trying to do

I have 3 models

Advice

AdviceLevel

Organisation

So the idea is:

An organisation can dispense more than 1 advice:

class Organsiation(models.Model):
    title = models.CharField(max_length=150)
    advice = models.ManyToManyField(Advice)

Ok BUT each advice subject within an organsiation needs to be graded as to a level capability 1 to 4
So in the model how can I effectively tie a foreign key to each advice selected in the ManyToMany field call?

Cheers for any enlightement
   
   

MikeKJ

unread,
Nov 7, 2013, 12:19:20 PM11/7/13
to django...@googlegroups.com
Think this may be a solution:

Models: Advice, AdviceLevel, Organisation


class Organsiation(models.Model):
    title = models.CharField(max_length=150)
    advice = models.ManyToManyField(Advice, through='AdviceLevel')
 
class AdviceLevel(models.Model):   
    advice = models.ForeignKey(Advice)
    organisation = models.ForeignKey(Organisation)
    level = models.IntegerField()

any comments?
   

Reply all
Reply to author
Forward
0 new messages