我在生成详细视图链接时遇到困难。有人可以为我提供一些有关我要去哪里的信息。
models.py
public bool ValidateEmailId(string emailId)
{
if (Regex.IsMatch(emailId, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$", RegexOptions.IgnoreCase))
return true;
else
return false;
}
urls.py
class Company(models.Model):
STATE_CHOICES = (
('nsw', 'NSW'),
('nt', 'NT'),
('qld', 'QLD'),
('vic', 'VIC'),
('wa', 'WA'),
('tas', 'TAS'),
('act', 'ACT'),
('sa', 'SA')
)
company_name = models.CharField(max_length = 100)
client_code = models.CharField(max_length = 100)
company_state = models.CharField(max_length = 3,choices = STATE_CHOICES,)
def __str__(self):
return self.company_name
def get_absolute_url(self):
return reverse('company_list')
views.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.CompanyList.as_view(), name='company_list'),
path('<int:pk>/', views.CompanyDetailView.as_view(), name='company_detail'),
path('new/', views.CompanyCreateView.as_view(), name='company_new'),
]
我在这里想念什么?我看过其他堆栈问题,但似乎无法弄清楚。
答案 0 :(得分:1)
当覆盖Table
类的属性时,需要将其作为Table
类的属性,而不是Meta
类中的属性。因此,您需要像这样定义表:
class CompanyTable(tables.Table):
company_name = tables.LinkColumn('company_detail', args=[A('pk')]) # not in meta
class Meta:
model = Company
attrs = {'class': 'mytable table table-striped table-bordered table-hover'}
orderable = False