How I can get the value of check radio button in update page

How I can get the value of check radio button in update page, it save it DB but in update page it did not show the selected radio button.

in models

user_role = models.CharField(max_length=25, default="USER")

in add html

<tr>
   <td class="mtrr"><b>User Role*</b></td>
   <td class="mtrr"><label class="radio-inline"><input type="radio" name="user_role" value="admin" checked>Admin</label></td>
   <td class="mtrr"><label class="radio-inline"><input type="radio" name="user_role" value="super">Super User</label></td>
   <td class="mtt"><label class="radio-inline"><input type="radio" name="user_role" value="user">User</label></td>
</tr>

in update add html

 <tr>
     <td class="mtrr"><b>User Role*</b></td>
     <td class="mtrr"><label class="radio-inline"><input {% if data.ul_role == True %} checked {% endif %} type="radio" name="user_role">Admin</label></td>
     <td class="mtrr"><label class="radio-inline"><input {% if data.ul_role == True %} checked {% endif %} type="radio" name="user_role">Super User</label></td>
     <td class="mtt"><label class="radio-inline"><input  {% if data.ul_role == True %} checked {% endif %}  type="radio" name="user_role">User</label></td>
</tr>

Your information is a bit incomplete as you left out the update view

You can solve your problem as follows

Add CHOICE attribute to your user_role field

In model:

class UserListGroup(models.Model):
    ROLE = (('user', 'USER'), ('admin', 'ADMIN'), ('super', 'SUPER USER')) 
    user_role = models.Charfield(max_length=25, choices=ROLES, default=user)

using choices will cause a html widget to be used, to use a radio button, create a Django form and update it as below

from Django forms import ModelForm, RadioSelect
from .models import UserListGroup

class UserListGroupForm(ModelForm):
    class Meta:
        model = UserListGroup
        field = '__all__'
        widgets = {
            'user_role': RadioSelect()
        }

Your add.html and update.html would look similar to

<form method="POST" action="">
    {% csrf_token %}
    {{ form }}
</form>

For such simple crude operation, you are better off using the Django generic view

On a final note, the approach you use in your update.html in checking for the current user role is wrong, as the condition is same in all three cases. It should be compared with their possible database values as follows

<tr>
     <td class="mtrr"><b>User Role*</b></td>
     <td class="mtrr"><label class="radio-inline"><input {% if data.ul_role == 'admin' %} checked {% endif %} type="radio" name="user_role">Admin</label></td>
     <td class="mtrr"><label class="radio-inline"><input {% if data.ul_role == 'super' %} checked {% endif %} type="radio" name="user_role">Super User</label></td>
     <td class="mtt"><label class="radio-inline"><input  {% if data.ul_role == 'user' %} checked {% endif %}  type="radio" name="user_role">User</label></td>
</tr>
Back to Top