I am trying to save the form I made in django which has a foreignkey from the client model to the client type model but at the time of saving this error comes out.
Can not assign "'1'": "Customer.type_client" must be to "Customer_type" instance
modelos.py
class TipoCliente(models.Model):
codigo = models.IntegerField()
descripcion = models.CharField(max_length=40)
class Cliente(models.Model):
tipo_cliente = models.ForeignKey('TipoCliente')
nombre = models.CharField(max_length=80)
views.py
tipo_cliente = TipoCliente.objects.all()
cliente = Cliente()
cliente.tipo_cliente = request.POST['tipo_cliente']
cliente.nombre = request.POST['nombre']
cliente.save()
error
ValueError at / general / clients
Can not assign "'1'": "Client.type_client" must be to "TypeClient" instance.
Django Version: 1.10.2
Exception Type: ValueError
Exception Value:
Can not assign "'1'": "Client.type_client" must be to "TypeClient" instance.
Using the Django form works perfectly but I have to do it without using the Django form.