0

I have models like below:

class Topic(MPTTModel):
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)  
    name = models.CharField(max_length=200, blank=False)
    tasks = models.ManyToManyField("Task", through="TopicTask")

class Task(models.Model):
    name = models.CharField(max_length=200, blank=False)
    madocs = models.ManyToManyField("Madoc", through="TaskMadoc")   

class TopicTask(models.Model):
    topic = models.ForeignKey("Topic")
    task = models.ForeignKey("Task")


class TaskMadoc(models.Model):
    task = models.ForeignKey("Task")
    madoc = models.ForeignKey("Madoc")

I tried

Task.objects.filter(madocs__id=1)

works well!

but when I tried

Topic.objects.filter(tasks__id=1)

the error is:

FieldError: Cannot resolve keyword 'tasks' into field. Choices are: children, created, id, level, lft, name, order, parent, parent_id, rght, studyplan, topictask, tree_id

So, choices don't have tasks!

Why? is mptt mess it?

Preshan Pradeepa
  • 698
  • 14
  • 31
lsaturn
  • 145
  • 1
  • 11

1 Answers1

1

Try

Topic.objects.filter(topictask__task__id=1)
madzohan
  • 11,488
  • 9
  • 40
  • 67