Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How are the <code>LinkedItem</code> associated with a <code>Page</code>? A <code>GenericRelation</code> is used for a reverse relationship, but as it stands now there isn't any relationship so it has nothing to match to. I think this is what you're looking for in your model design:</p> <pre><code>class Page(models.Model): body = models.TextField() # Moved generic relation to below class LinkedItem(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') # LinkedItems now relate to a Page model, and we're establishing the relationship # by specifying 'links' to keep the syntax you're looking for page = models.ForeignKey(Page, related_name='links') title = models.CharField(max_length=100) </code></pre> <p>On a side note, this model setup allows one <code>LinkedItem</code> to relate to a <code>Page</code>. If you wanted to re-use linkeditems, you could make it a M2M:</p> <pre><code>class Page(models.Model): body = models.TextField() links = models.ManyToManyField(LinkedItem) class LinkedItem(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') title = models.CharField(max_length=100) </code></pre> <p>In both of these instances, page.links.all() will be all of the linked items.</p> <p>Also, parenthesis aren't used in the template syntax.</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