Я боролся с этим весь день, я уже реализовал CreateView, и он работает нормально, теперь, когда я пытаюсь выполнить Обновление с UpdateView (CBV), я получаю эту ошибку:
Request Method: GET
Request URL: http://127.0.0.1:8000/drivers/edit/2/
Django Version: 3.0.2
Exception Type: AttributeError
Exception Value:
'function' object has no attribute '_default_manager' Exception
Location: C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\lib\site-packages\django\views\generic\detail.py
in get_queryset, line 67 Python
Executable: C:\Users\jorge.lopez\.virtualenvs\Carros-ZVuxKBiy\Scripts\python.exe
Python Version: 3.7.3
полная трассировка: [http://dpaste.com/3Z7YFMD]
model.py
class conductores(models.Model):
nombres = models.CharField(max_length=25)
apellidos = models.CharField(max_length=25)
edad = models.IntegerField()
phone_regex = RegexValidator(
regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
# validators should be a list
telefono = models.CharField(
validators=[phone_regex], max_length=17, blank=True)
ine = models.FileField(upload_to='INE/', blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
unique_together = ('nombres', 'apellidos')
verbose_name_plural = "Conductores"
def __str__(self):
return '%s %s' % (self.nombres, self.apellidos)
def get_absolute_url(self):
return reverse('conductores')
urls.py
urlpatterns = [
path('', views.index, name='index'),
# path('conductores_sort/',
# views.conductores_sort.as_view(), name='conductores_sort'),
path('conductores_list/', views.conductores),
path('drivers/', views.ConductoresListView.as_view(), name='conductores'),
path('drivers/add/', views.ConductoresCreate.as_view(), name='conductor_new'),
path('drivers/edit/<int:pk>/',
views.ConductoresUpdate.as_view(), name='conductor_edit'),
]
views.py
class ConductoresCreate(CreateView):
form_class = PostConductores
template_name = "AC/add_driver.html"
class ConductoresUpdate(UpdateView):
model = conductores
fields = ('nombres', 'apellidos', 'telefono', 'edad', 'ine')