Начальная ошибка: когда CustomerID был CharField в models.py:
![Error Message :](https://i.stack.imgur.com/mhOBh.png)
после внесения изменений в модель и внесенияCustomerID UUIDField , получая следующую ошибку:
![enter image description here](https://i.stack.imgur.com/2LBTr.png)
Я пытаюсь перенаправить на представление на основе CustomerID, но это не такработает на UUID.Ранее он работал нормально с целыми числами.
Пожалуйста, предложите.
url.py:
from django.urls import path, include
from . import views
urlpatterns = [
path('create/', views.create, name='create'),
path('<uuid:customer_id>', views.detail, name='detail'),
path('search/customers/<uuid:customer_id>', views.detail, name='detail'),
path('customers/<uuid:customer_id>', views.detail, name='detail'),
path('edit/<uuid:customer_id>', views.edit, name='edit'),
path('modify/<uuid:customer_id>', views.modify, name='modify'),
]
views.py
@login_required
def detail(request, customer_id):
customer = get_object_or_404(CustomerMaster, pk=customer_id)
return render(request, 'customers/detail.html',{'customer':customer})
моделей.py
class CustomerMaster(models.Model):
customerid = models.UUIDField(db_column='CustomerID', primary_key=True) # Field name made lowercase.
customernumber = models.CharField(db_column='CustomerNumber', max_length=50) # Field name made lowercase.
customername = models.CharField(db_column='CustomerName', max_length=50) # Field name made lowercase.
lastmodifiedutc = models.DateTimeField(db_column='LastModifiedUTC') # Field name made lowercase.
lastmodifiedby = models.CharField(db_column='LastModifiedBy', max_length=50) # Field name made lowercase.
active = models.BooleanField(db_column='Active') # Field name made lowercase.
customershortname = models.CharField(db_column='CustomerShortName', max_length=50, blank=True, null=True) # Field name made lowercase.
class Meta:
managed = False
db_table = 'Customer_Master'
def __str__(self):
return self.CustomerName