Can't able to get the id of the model instance in django when i connect the project to MongoDB
I am doing the simple CRUD in djnago project ,first i was working with sqlite that is by default in djnago ,every thing was working properly,but when i configure it with MongoDB ,now create and read operations are working properly ,but for update and delete ,i can't able to get the id of the instance to send it to url with request, getting the error ,, ValueError at /employe/update/None
when i try this '<form action="{% url 'update' i.id %}" method="POST">' and when i try to use <form action="{% url 'update' i._id %}" method="POST"Field 'id' expected a number but got 'None'.> _id as it is identifier in mongoDB ,then the syntax arrive comes that attribute can't start with '_',,
ValueError at /employe/update/None
when i try this '<form action="{% url 'update' i.id %}" method="POST">' and when i try to use <form action="{% url 'update' i._id %}" method="POST"Field 'id' expected a number but got 'None'.> _id as it is identifier in mongoDB ,then the syntax arrive comes that attribute can't start with '_',,
Django's models have a .pk
attribute that returns the primary key, regardless what field that contains the primary key.
So you can use:
{% url 'update' i.pk %}