1
Good afternoon, everyone.
I have a model in Django with a field - phone - which is a unique key:
phone = models.CharField(max_length=11, unique=True)
I’m trying to generate a form in which the user enters the site and puts the phone, but I’m getting error saying that the phone is already at the base. My goal is precisely that the phone is at the base.
form py.
class ClientForm(forms.ModelForm):
class Meta:
model = Client
fields = ('phone', )
html template.
<form method="POST" class="client-form">
{% csrf_token %}
{{ form.phone }}
<button type="submit" class="save btn">CONTINUAR</button>
</form>
py views.
def get_phone(request):
if request.method == "POST":
if form.is_valid():
phone = form.cleaned_data['phone']
client = Client.objects.filter(phone=phone).first()
The problem is he’s just form.is_valid()
.
What I have to do differently for him to understand that I want to make a query of a number that already exists?