In [23]: perc = Perception.objects.all()
In [24]: list = []
In [25]: for item in perc:
...: if item.loan.request.customer_id not in list:
...: print(item.loan.request.customer.user.last_name, item.loan.requ
...: est.customer.user.first_name)
...: list.append(item.loan.request.customer_id)
...:
(u'Kshlerin', u'Dwight')
(u'Boyer', u'Keshaun')
このようなループをテンプレートに再現したいと思います。ここでDjangoのテンプレートで再現
は、そのテンプレートに関連した図である。
class PerceptionIndexView(StaffRestrictedMixin, FrontendListView):
page_title = _('Perception')
model = Perception
template_name = 'loanwolf/perception/index.html'
pjax_template_name = 'loanwolf/perception/index.pjax.html'
#row_actions_template_name = 'loanwolf/perception/list-actions.inc.html'
url_namespace = 'perception'
#def get_icon(self, req):
# return icon(req.get_icon(), css_class=get_request_color(req, text=True))
def active(self, obj):
if obj.is_active:
return icon(obj.get_icon(), css_class='green-text', tooltip=_('Active'))
else:
return icon(obj.get_icon(), css_class='red-text', tooltip=_('Inactive'))
def get_customer(self, req):
return 'test'
#url = reverse('customers:profile', kwargs={'cust': req.customer.user.pk})
#return '<a href="%s">%s</a>' % (url, req.customer)
def notes_count(self, obj):
return obj.notes.count()
notes_count_label = _('Notes')
def get_change_url(self, obj):
return obj.get_absolute_url()
class Meta:
ordering = ('-created', '-modified')
sortable = ('start_date', 'end_date', 'created', 'state', 'modified')
list_filter = ('state', 'is_active')
list_display = (
'loan', 'state', 'start_date', 'end_date', 'current_balance',
'operation_error', 'modified', 'created', 'notes_count', 'active'
)
、ここでは、そのテンプレートに関連したモデルです。
@python_2_unicode_compatible
class Perception(xwf_models.WorkflowEnabled, TimeStampedModel):
loan = models.ForeignKey('loans.Loan')
state = xwf_models.StateField(PerceptionWorkflow)
start_date = models.DateField(_('Start date'))
end_date = models.DateField(_('End date'), blank=True, null=True)
current_balance = models.DecimalField(_('Current balance'),
default=0, decimal_places=2, max_digits=11)
operation_error = models.SmallIntegerField(_('Operation error'), default=0)
notes = GenericRelation(Note)
私はそのようなことを再現するtemplatetagを使用できると思ったが、私はもっと簡単にしたいです。誰でも私のテンプレートに実装するために何ができるのか教えていただけますか?実際、私の問題の1つは、Djangoのテンプレート内にリストを作成することです。
をループすることができます'perc'変数?あなたはテンプレートのリストで何をしたいですか? – Alasdair
あなたは 'user = item.loan.request.customer.user'を必死にしています – thebjorn
ごめんなさい、私は私の質問を変更します。 –