I thought better, and I think I'll use json.
def entry_detail_json(request, pk):
data = Entry.objects.filter(pk=pk)
s = serializers.serialize("json", data)
return HttpResponse(s)
But being on the page
http://localhost:8000/entry/2/
How do I refer to the page
http://localhost:8000/entry/json/2/
And assign the values in the following function to copy the data?
I got the result as follows:
<input name="new_proposal" type="submit" class="btn btn-primary" value="{{ entry.id }}"
views.py
def create_proposal(request, employee_pk=1, **kwargs):
f = None
if request.method == 'GET':
f = request.GET['new_proposal']
if f:
employee = Employee.objects.get(pk=employee_pk) # TODO
nlp = NumLastProposal.objects.get(pk=1) # sempre pk=1
# entry = Entry.objects.get(pk=kwargs.get('pk', None))
entry = Entry.objects.get(pk=f)
obj = Proposal(
num_prop=nlp.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()
# Define que foi dado entrada
entry.is_entry = True
entry.save()
# Incrementa o número do último orçamento
nlp.num_last_prop += 1
nlp.save()
print('Orçamento criado com sucesso')
return redirect('proposal_list')
It's working, but I know it's not the best way to handle it.
And in the end I ended up not using JSON. How would I do to use JSON instead of doing as I did?
[{"pk": 2, "fields": {"work": 2, "description": "Ih1vwUcIYwc0ce", "created": "2015-07-31T19:41:04.408Z", "priority": "u", "category": 1, "person": 45, "seller": 2, "is_entry": true, "modified": "2015-07-31T21:11:59.165Z"}, "model": "core.entry"}]