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')
Ich möchte solche Schleife in der Vorlage reproduzieren.Reproduzieren in einem Django-Vorlage
Hier ist die Ansicht zu dieser Vorlage bezogen werden:
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'
)
und hier wird das Modell zu dieser Vorlage bezogen werden:
@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)
Ich dachte, ich TemplateTag verwenden könnte so etwas zu reproduzieren, aber Ich möchte etwas leichter haben. Könnte mir jemand sagen, was ich tun könnte, um das in meiner Vorlage zu implementieren? Eines meiner Probleme besteht darin, eine Liste innerhalb einer Django-Vorlage zu erstellen.
Was sind die 'perc' Variable? Was möchten Sie mit der Liste in der Vorlage tun? – Alasdair
Sie brauchen dringend einen 'user = item.loan.request.customer.user' – thebjorn
Sorry Leute, ich werde meine Frage ändern. –