Consider my template:
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>
And consider my views:
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()
Question : How do I make this work? I need to get the entry.pk of the page I am, in this case, entry.pk, I am on this page because I am in DetailView.
entry = Entry.objects.get(pk=self.request.GET[self.id])
Using manage.py shell works, but in the template I need to choose Entry, that is, get pk.
# 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()