I want to change the primary key being sent to the update view from the template. Let me explain. Here is my template:
<a href="{% url 'new_url' model_instance.pk %}">
{{ model_instance.username }}
</a>
This model_instance is an instance in a for loop of the context variable model_instances in a list view. This primary key of the model_instance will then be sent to the following view:
class UserUpdateView(generic.UpdateView):
template_name = "leads/update.html"
queryset = User.objects.all()
context_object_name = "user"
form_class = UserUpdateForm
def get_success_url(self):
return reverse("some-url")
However, the problem is that the primary key I am sending to UserUpdateView is the primary key for the model_instance model, not the User model. Moreover, there is no link like one-to-one relationships between the two models. However, there is a similarity. Both of the model_instance and user each have a username field that are the same.
In other words, I need to first retrieve the model_instance.username, and then query the User model to find the user instance with the same username I want to update. At the moment, the UserUpdateView is simply receiving the primary key for a model_instance in the template, which is not what I want. I hope you guys can help me with this issue, and please leave any questions you have. Thank you.