# Challenges Updating a built in function form in python

**URL:** <https://forum.djangoproject.com/t/challenges-updating-a-built-in-function-form-in-python/21056>\
**Category:** Forms & APIs\
**Created:** [May 21, 2023, 9:31am UTC](https://forum.djangoproject.com/t/challenges-updating-a-built-in-function-form-in-python/21056 "2023-05-21T09:31:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![realemma](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/realemma/32/13813_2.png) [@realemma](https://forum.djangoproject.com/u/realemma)\
**Post date:** [May 21, 2023, 9:31am UTC](https://forum.djangoproject.com/t/challenges-updating-a-built-in-function-form-in-python/21056/1 "2023-05-21T09:31:27Z")

</div>

I am having challenges whenever i try to update the form is not working , it jumps to else branch try all measure to check for error

view part:

```auto
def clients_edit(request, pk):
     client = Client.objects.filter(created_by=request.user).get(pk=pk)

    if request.method == 'POST':
        form = AddClientForm(request.POST, instance=client)

        if form.is_valid():
            form.save()
            messages.success(request, "The changes were saved.")
            return redirect('clients_list')
        
    else:
        form = AddClientForm(instance=client)

    return render(request, 'clients/clients_edit.html', {'form': form})

```

url : `path('<int:pk>/edit', views.clients_edit, name='clients_edit'),`

html:

```auto
   <form method="POST" action=".">

            {% csrf_token %}

            {{ form.as_p }}

            <button class="py-4 px-8 bg-teal-500 text-white rounded-xl">Submit</button>
        </form>

```

form.py :

```auto
class AddClientForm(forms.ModelForm):
    class Meta:
        model = Client
        fields = ('name', 'email' , 'desription',)

```

---

<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:** [May 21, 2023, 12:27pm UTC](https://forum.djangoproject.com/t/challenges-updating-a-built-in-function-form-in-python/21056/2 "2023-05-21T12:27:42Z")

</div>

Side note: When posting code here, please surround each file’s code between lines of three backtick - ` characters. This means you’ll have a line of ```, then the code, then another line of ```. This forces the forum software to keep your code properly formatted. (I have taken the liberty of editing this post for you.)

Have you verified that the instance of Client you are trying to edit was actually created by the user currently logged on?

Are you getting any error messages on the console where you’re running runserver?

Can you post your `Client` model?

You might want to add an `else` clause on the `if form.is_valid()` conditional to print the errors generated within the form. That might help identify the issue.

---

<div class="post-metadata">

**Author:** ![realemma](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/realemma/32/13813_2.png) [@realemma](https://forum.djangoproject.com/u/realemma)\
**Post date:** [May 21, 2023, 1:59pm UTC](https://forum.djangoproject.com/t/challenges-updating-a-built-in-function-form-in-python/21056/3 "2023-05-21T13:59:38Z")

</div>

no error message displayed

— from django.db import models

# Create your models here.

from django.contrib.auth.models import User  
from django.db import models

from team.models import Team

# Create your models here.

class Client(models.Model):  
name = models.CharField(max\_length=120)  
email = models.EmailField()  
desription = models.TextField(blank=True, null=True)  
created\_by = models.ForeignKey(User, related\_name=‘clients’, on\_delete=models.CASCADE)  
created\_at = models.DateTimeField(auto\_now\_add=True)  
modified\_at = models.DateTimeField(auto\_now=True)

```
class Meta:
    ordering = ('name',)

def __str__ (self):
    return self.name

```
