How to pass model instance pk to template from Django modelformset?

I have a model that I want to display in a template with a modelformset. I want to be able to delete instances of the model by pressing a button in the template, but I can't seem to pass the instance's pk. The "id" field only passes a huge boundfield that generates and error when I use it for the delete button.

Is there any way to pass the instance's pk to the template?

class Activity(Model):
    user = ForeignKey(settings.AUTH_USER_MODEL, on_delete=CASCADE)
    activity = CharField(max_length=100, default='')
    number = IntegerField(default=1)

    def __str__(self):
        return self.activity

Built in a formset:

activities = Activity.objects.filter(user=request.user)
pre_formset = modelformset_factory(Activity, fields=('activity', 'number', 'id',))
formset = pre_formset(queryset=activities)


             { formset.management_form }}
            {% for activity in formset %}
                {{ }}
                {{ activity.ORDER }}
                {{ activity.DELETE }}
                    {% if not forloop.first %}
                    <a class="btn" href="{% url 'activity_delete' %}"
                    onclick="return confirm('Are you sure you want to delete this activity?')">X</a>
                    {% endif %}
                    {% endfor %}
Back to Top