title: Check if member value is different than in previous iteration
body: <p>I have a <code>QuerySet</code> of <code>GroupMembership</code> objects ordered by <code>product__name</code>, which is assigned to my template as <code>group_memberships</code>; <code>GroupMembership</code> objects have a <code>product</code> and a <code>group</code> field, both having a <code>name</code> property. In the output I’d like to render a heading tag every time <code>membership.product.name</code> changes:</p>
  
  <pre><code>&lt;h1&gt;First Product&lt;/h1&gt;
  &lt;p&gt;One item&lt;/p&gt;
  &lt;p&gt;Another item&lt;/p&gt;
  &lt;h1&gt;Second Product&lt;/h1&gt;
  &lt;p&gt;First item in Second Product&lt;/p&gt;
  </code></pre>
  
  <p>My original idea was to introduce a helper variable where I store the last product name, and if it is different from the previous one (or empty), I render the <code>&lt;h1&gt;</code> line. Django, however, lacks an <code>{% assign %}</code> tag. Is there a way to do it without introducing a custom template tag/context processor? Or should I instead do the grouping somehow in my view, and assign a nested <code>dict</code> to my template? I prefer not to install any custom app for this matter.</p>