title: access to pk in a template form
body: <p>I want to display all elements of a form including the pk and I have not found a satisfying method to do so:</p>
  <pre><code>class SomeForm(forms.Form):
      def __init__(self, *args, **kwargs):
          super().__init__(*args, **kwargs)
          self.fields[&quot;number&quot;] = forms.IntegerField(required = True)
          self.fields[&quot;id&quot;] = forms.IntegerField(disabled = True)
          self.fields[&quot;data&quot;] = forms.CharField(required = False)
          
      class Meta:
          model = SomeModel
          fields = [&quot;id&quot;, &quot;number&quot;, &quot;data&quot;]
  </code></pre>
  <p>So now I just call the form in the view with:</p>
  <pre><code>class SomeView(TemplateView):
      template_name = &quot;app/sometemplate.html&quot;
  
      def get_context_data(self, **kwargs):
          context = super().get_context_data(**kwargs)
          obj = MODEL.objects.get(pk = context[&quot;pk&quot;])
          MODEL_data = {}
          MODEL_data[&quot;number&quot;] = obj.number
          MODEL_data[&quot;id&quot;] = obj.pk
          MODEL_data[&quot;data&quot;] = obj.data
  
          context[&quot;form&quot;] = SomeForm(initial = MODEL_data)
          return context
  </code></pre>
  <p>and now in the templatetags I have a filter <code>get_pk</code>:</p>
  <pre><code>@register.filter(name='get_pk')
  def get_pk(obj):
      return obj.initial[&quot;id&quot;]
  </code></pre>
  <p>and I get the <code>pk</code> in the template with <code>{{ form|get_pk }}</code> and I feel like this is not smart. I tried stuff like <code>{{ form.instance.id }}</code> like suggested <a href="https://stackoverflow.com/a/68054522/4225972">here</a>. I still feel there must be an easy way to achieve this?</p>