Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Like <a href="https://stackoverflow.com/questions/17723890/how-to-reference-objects-with-generic-foreignkey-reference-in-django#comment25834458_17723890">user710907 says</a>, Maintenance.taskRef.all() should do the trick. When you specify a ForeignKey relation, you can set a "related_name" argument that is used for the reverse relationship. If you don't specify, this defaults to "model_name_set".</p> <pre><code>class Foo(models.Model): ... class Bar(models.Model): ... foo = models.ForeignKey(Foo, related_name="related_bars") </code></pre> <p>Now you can access that relationship via <code>bar.foo</code> from the one side, or <code>foo.related_bars</code> from the other. If you don't specify, the latter argument will default to <code>foo.bar_set</code>.</p> <p>In your example, you define the relationship from both sides; the FK is defined on Task, and the reference is defined on Maintenance and Template. Since you've provided fields on both models that handle the relationship, there's no need to provide a maintenance_set default.</p> <p>edit: Upon further inspection, I think part of the confusion might be around your <code>Task.maintenance</code> field. If I'm not mistaken, that's the field you want to point to either <code>Maintenance</code> <em>or</em> <code>Template</code>, right? So why is it called <code>maintenance</code>? I definitely recommend reading <a href="https://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1" rel="nofollow noreferrer">this section of the docs</a> too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload