Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The error in question is caused when you try to access the <code>Manager</code> of a model through an instance of the model. You have used <em>lower case</em> class names. This makes it hard to say if the error is caused by an instance accessing the <code>Manager</code> or not. Since other scenarios that can cause this error are unknown I am proceeding on the assumption that you have somehow mixed up the <code>topic</code> variable so that you end up pointing to an instance of the <code>topic</code> model instead of the class. </p> <p>This line is the culprit: </p> <pre><code>forum.topic_count = topic.objects.filter(forum = forum).count() # ^^^^^ </code></pre> <p>You have to use:</p> <pre><code>forum.topic_count = Topic.objects.filter(forum = forum).count() # ^^^^^ # Model, not instance. </code></pre> <p>What is going wrong? <code>objects</code> is a <code>Manager</code> available at the class level, not to the instances. See the <a href="http://docs.djangoproject.com/en/dev/topics/db/queries/#retrieving-objects" rel="noreferrer">documentation for retrieving objects</a> for details. Money quote:</p> <blockquote> <p><code>Managers</code> are accessible <strong><em>only</em></strong> via model classes, rather than from model instances, to enforce a separation between "table-level" operations and "record-level" operations.</p> </blockquote> <p>(Emphasis added)</p> <p><strong>Update</strong></p> <p>See the comments from @Daniel below. It is a good idea (nay, you MUST :P) to use title case for class names. For instance <code>Topic</code> instead of <code>topic</code>. Your class names cause some confusion whether you are referring to an instance or a class. Since the <code>Manager isn't accessible via &lt;model&gt; instances</code> is very specific I am able to offer a solution.The error may not be so self evident always. </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.
    3. 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