last day (15 days later) » 

6:56 PM
0
A: Django Open / Edit record instead of Creating new

Hasan Ramezaniuse this: def customeradd(request, id=None): if id: customer = Customer.objects.get(pk = id) else: customer = Customer() if request.method == 'POST': form = CustomerAddForm(request.POST, instance=customer) if form.is_valid(): form.save() ...

 
I tried this before, it creates the error; customeradd() takes exactly 2 arguments (1 given). Because no id is given with submit.
 
check my edit. and remove CustomerAddForm constructor
 
I edited the views.py but still it creates a new record. I am not sure where to remove CustomerAddForm? I also checked crispy-forms website and they mention something like form.helper.form_action = reverse('/customeroverview/', args=[Customer.pk]) but this creates an error; Reverse for '/customeradd/' with arguments '(<property object at 0x00000000033D7278>,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
keep in mind, if i set the id=1 it will save the alterations to id 1. So it seems no id is received in the view when clicking on submit on the form.
 
please add customer-add.html template in question.
 
customer-add.html is now in the question. (crispy-form)
 
6:56 PM
replace self.helper.form_action = '/customeradd/' with self.helper.form_action = '.'
 
Again, the record saves as a new one. - shouldn't i add the customer.pk in the action (or something in that direction)?
 
hi dude
 
Hi Hasan, thank you for helping me
 
your welcome
 
What would be the best approach for me to give you the insights you need.
if interested i could send you the repository
 
6:58 PM
give me the url, when you go to edit a customer
 
url(r'^customeradd/(?P<id>\w+)$', 'customer.views.customeradd', name='customeropen'),
 
no, give the url from browser
 
<td><a href='{% url "customeropen" customer.id %}'>{{ customer.customer_name }}</a></td>
i could host the project if you mean thath
 
yes please
 
i have it running but an error occours after submit
static issue, ill try to fix it quickly
 
7:10 PM
ok
dude replace self.helper.form_action = '.' with self.helper.form_action = '' please
 
thats it!
could you briefly explain what the difference is ?
 
problem fixed?
 
yes! problem fixed
 
my english writing is very bad dude . i am from iran
sorry i can explain it for you :(
 
ok! well thank you very much
greetings from amsterdam
if you edit your answer i will accept it
 
7:21 PM
thanks dude . i do it
done
thanks dude.
 
you too!
 
your welcome
 
7:41 PM
bye dudes.
 

last day (15 days later) »