# Create a Modelform which can only be submitted by 1 person at a time?

**URL:** <https://forum.djangoproject.com/t/create-a-modelform-which-can-only-be-submitted-by-1-person-at-a-time/19790>\
**Category:** Using the ORM\
**Created:** [March 25, 2023, 3:09pm UTC](https://forum.djangoproject.com/t/create-a-modelform-which-can-only-be-submitted-by-1-person-at-a-time/19790 "2023-03-25T15:09:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepankar-98](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/deepankar-98/32/12897_2.png) [@Deepankar-98](https://forum.djangoproject.com/u/Deepankar-98)\
**Post date:** [March 25, 2023, 3:09pm UTC](https://forum.djangoproject.com/t/create-a-modelform-which-can-only-be-submitted-by-1-person-at-a-time/19790/1 "2023-03-25T15:09:38Z")

</div>

Hi All,

I am facing a challenge and giving a brief intro for better understanding of the problem:

I am working on a functionality, where a DB table is having a field **status** with valid choices as **assigned** and **un-assigned**.

I have used ListView class to display the model data as a table and added a column which has a button called “Assign”.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/a/a7a57194ee12542aa80829eac381159489533c6c.png)

On clicking on assign an **Assignment form** will open up and they can submit. Once this form is submitted the status will change to **assigned** and the assignment button will disappear. All this is fine and done already.

1. Now the challenge is to design such that whichever user clicks on assign first will get the option to assign it only and any consecutive users who try to click on assign will not be allowed to assign.

2. Also there has to be check in the “Assignment form” submit (POST method) view to check if that process status is already updated to “Assigned”.

This problem mainly arises when 2 users have opened the page some time back and without refreshing the page they are trying to click on “Assign” button.

It would be life saving if someone can help me out with this.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 25, 2023, 3:36pm UTC](https://forum.djangoproject.com/t/create-a-modelform-which-can-only-be-submitted-by-1-person-at-a-time/19790/2 "2023-03-25T15:36:51Z")

</div>

In your view that handles the button press, check the status of the object before assigning it. If it’s already assigned, do what you need to do in that situation.

In the simple case, this is going to cover 99+% of what’s going to happen. If you need it to be even _more_ precise, use the [`select_for_update`](https://docs.djangoproject.com/en/4.1/ref/models/querysets/#select-for-update) function to retrieve the row to be tested.

We can’t be more specific without seeing the view being used here.

---

<div class="post-metadata">

**Author:** ![Deepankar-98](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/deepankar-98/32/12897_2.png) [@Deepankar-98](https://forum.djangoproject.com/u/Deepankar-98)\
**Post date:** [March 26, 2023, 1:39am UTC](https://forum.djangoproject.com/t/create-a-modelform-which-can-only-be-submitted-by-1-person-at-a-time/19790/3 "2023-03-26T01:39:54Z")

</div>

Thanks for the help.  
Let me read on this somewhat and then get back to you if required.

---

<div class="post-metadata">

**Author:** ![Deepankar-98](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/deepankar-98/32/12897_2.png) [@Deepankar-98](https://forum.djangoproject.com/u/Deepankar-98)\
**Post date:** [April 8, 2023, 2:50am UTC](https://forum.djangoproject.com/t/create-a-modelform-which-can-only-be-submitted-by-1-person-at-a-time/19790/4 "2023-04-08T02:50:34Z")

</div>

I implemented the [`select_for_update`](https://docs.djangoproject.com/en/4.1/ref/models/querysets/#select-for-update) function and transaction.atomic.

But how do I test it if its working as expected?
