-1
考慮我的模板:如何複製與登記的DetailView,讓PK(Django的)
entry_detail.html
<form class="navbar-form navbar-right" action="." method="get">
<!-- add -->
<!-- <p name="filter_link" class="pull-right"><a href="">Produtos em baixo estoque</a></p> -->
<a name="new_customer" href="{% url 'proposal_list' %}">
<button type="button" class="btn btn-primary">
<span class="glyphicon glyphicon-plus"></span> Criar Orçamento
</button>
</a>
</form>
而且considerer我的觀點:
views.py
class EntryDetail(DetailView):
template_name = 'core/entry/entry_detail.html'
model = Entry
def create_proposal(self, employee_pk=8):
if 'new_customer' in self.request.GET:
employee = Employee.objects.get(pk=employee_pk)
num_last_proposal = NumLastProposal.objects.get(
pk=1) # sempre pk=1
entry = Entry.objects.get(pk=self.request.GET[self.id])
obj = Proposal(
num_prop=num_last_proposal.num_last_prop + 1,
type_prop='R',
category=entry.category,
description=entry.description,
work=entry.work,
person=entry.person,
employee=employee,
seller=entry.seller,
)
obj.save()
entry.is_entry = True
entry.save()
num_last_proposal.num_last_prop += 1
num_last_proposal.save()
問題:如何使這個工作。如何獲得entry.pk中的DetailView用於
entry = Entry.objects.get(pk=self.request.GET[self.id])
在manage.py殼工作
shell_create_proposal.py
from core.models import Entry, Proposal, Employee, NumLastProposal
employee = Employee.objects.get(pk=8)
num_last_proposal = NumLastProposal.objects.get(pk=1)
entry = Entry.objects.get(pk=1)
obj = Proposal(
num_prop=num_last_proposal.num_last_prop + 1,
type_prop='R',
category=entry.category,
description=entry.description,
work=entry.work,
person=entry.person,
employee=employee,
seller=entry.seller,
)
obj.save()
entry.is_entry = True
entry.save()
num_last_proposal.num_last_prop = num_last_proposal.num_last_prop + 1
num_last_proposal.save()
這個我知道,問題是如何獲得的PK鑑於複製數據。 –
我更新了答案,以顯示get對象方法如何實現它。你可以在我給你看的網頁上查看它。 –