Doragonsureiyā
I have coded this in over 6 different ways and each iteration successfully updates but painfully creates an updated record
Please provide a full explanation including all the details that you consider relevant. Your statement is too broad and there is no clear way to answer you, you have to explain:
- what you're doing
- what you're expecting
- what you're using
- where you're running the script
- what Python version you're using
- what packages and their versions you're using
- and the most important thing: show the code YOU wrote (read rule 5️⃣ for that)
and more details, that way your chances to get help will increase.
🦍S6t0m1 🍃🦂
🦍S6t0m1 🍃🦂
Django 4.2.6
cj
🦍S6t0m1 🍃🦂
Yes
cj
🦍S6t0m1 🍃🦂
Wouldnt my issue be in the post because i am retrieving the values proper and all its just that after submitting updates, a new updated record is created rather than the same record being overwritten
cj
奈姆
The code that you've shared looks right tho.
🦍S6t0m1 🍃🦂
That'll cloud the DB if each update produces a new record
奈姆
🦍S6t0m1 🍃🦂
https://pastebin.com/DQeQig6p
🦍S6t0m1 🍃🦂
https://pastebin.com/DQeQig6p
Here is each implementation i coded to update a view , all successfully updates but all painfully creates that other record
🦍S6t0m1 🍃🦂
🦍S6t0m1 🍃🦂
class Lab(models.Model): PKlab = models.BigAutoField(primary_key=True) - Pastebin.com
https://pastebin.com/FThUz9uE
🦍S6t0m1 🍃🦂
Bakhtiyarov
Hello! Which django admin library has modern beautifull design?
Charly
The Inspired
Models
I'm having trouble understanding your problem. What exactly is your problem again?
The Inspired
that shouldn't be happening
The Inspired
unless they have used POST method to update also
i am osho
hey , i am not able to import forms to my html code , everything is running correctly even getting output without any problem but just form part is not showing in the website ,
i am osho
{% extends "enrol/base.html" %}
{% block content %}
<h1> Add New Student</h2>
<form action="" method="POST">
{% csrf_token %}
{{form}}
<button type="submit" class="btn btn-success">Add</button>
</form>
{% endblock content%}
i am osho
this is my code .
奈姆
i am osho
no bro its not working this way also
奈姆
Bakhtiyarov
Joe
The Inspired
Doragonsureiyā
Impossible to help without details.
Read this please:
http://www.catb.org/~esr/faqs/smart-questions.html
cj
that's a very self-explanatory error
Enlighting-man
mansurbekh
Hi all how to upload django project to free server
mansurbekh
mansurbekh
mansurbekh
should work 24/7 when accessing the site
Sheljin
we can hoist our django project to pythonanywhere for free
Sheljin
it will be accessible 24/7
奈姆
500: INTERNAL_SERVER_ERROR
I don't use Vercel. You have to figure out (google) how to find the logs...
maybe here: https://vercel.com/docs/functions/logs
شهرزاد محمد
Samir
Alison
Hi guys! I have a question, I have performance losses when using too much template inheritance?
clouded
.terrri
if request.method == 'PATCH':
id=pk
employee=EmployeeList.objects.get(pk=id)
serializer=EmployeeSerializer(employee,data=request.data,partial=True)
if serializer.is_valid():
serializer.save()
return Response({'msg': 'Patch updated partially'})
return Response(serializer.errors)
From the front-end does it accept only updated fields or all the fields
sanket 💜
sanket 💜
export const updateEmployee = async (id, updatedEmployee) => {
try {
const response = await fetch(http://127.0.0.1:8000/employees/api/${id}, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(updatedEmployee),
});
console.log("updating..", JSON.stringify(updatedEmployee));
Is this correct format but it's showing undefined 404 not found what may be the root cause I am unable to find it out
verify the url http://127.0.0.1:8000/employees/api/${id} into the backend
Ex: path('employees/api/<int:pk>/', EmployeeDetailView.as_view(), name='employee-detail'),
Make sure from the front end side you are passing the id correctly.
(Try to debug everything)
Also make sure there that you have installed the required Middleware
like: django-cors-headers
And before testing it directly into front end try to test this API in postman or thunder client.
.terrri
sanket 💜
Can you please share the code which is written for this functionality.
from
urls, views & serializers.
Carlos Alberto
export const updateEmployee = async (id, updatedEmployee) => {
try {
const response = await fetch(http://127.0.0.1:8000/employees/api/${id}, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(updatedEmployee),
});
console.log("updating..", JSON.stringify(updatedEmployee));
Is this correct format but it's showing undefined 404 not found what may be the root cause I am unable to find it out
Use this code instead
export const updateEmployee = async (id, updatedEmployee) => {
try {
const response = await fetch(`http://127.0.0.1:8000/employees/api/${id}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(updatedEmployee),
});
console.log("Updating...", JSON.stringify(updatedEmployee));
if (!response.ok) {
throw new Error(`Error updating employee: ${response.status} ${response.statusText}`);
}
const data = await response.json();
console.log("Updated employee:", data);
return data;
} catch (error) {
console.error("Failed to update employee:", error.message);
throw error; // Re-throw the error for further handling in the caller function.
}
};
Emmanuel
.terrri
Светлана
Help please. I have a mistake Skipping analyzing "django.urls": module is installed, but missing library stubs or py.typed marker.
Prabhakar
Issue on views.py bro
Doragonsureiyā
Issue on views.py bro
Read this please:
http://www.catb.org/~esr/faqs/smart-questions.html
நட்புடன்
I wanna create a custom user
like Employee with relevant details
I am stuck in authentications
Can any one guide me
even with any tutorial link is fine
I am a newbie in Django
S
I have to implement payment integration from one user to another user in my Django project, how can i do that?
hadi
Hi how can I integrate crypto currency payment in my project ?
Кит
What do you think is the best way to make it possible to receive notifications in real time? So that the client simply pings the server with a request: "Are there new notifications?" Or do tracking via the Redis broker, which will send them to the client via Server-Sent Events?
Jose
CodeThlete
Hi, I have some issues with csrfmiddlewaretoken. I am able to add new user with old csrfmiddlewaretoken in django's admin panel
Why it's happening??
this is my settings.py
'django.middleware.csrf.CsrfViewMiddleware',
CSRF_USE_SESSIONS = True
# CSRF_COOKIE_SECURE = False # Ensures the CSRF cookie is only sent over HTTPS
CSRF_COOKIE_HTTPONLY = True # Ensures the CSRF cookie is not accessible via JavaScript
#csrf cookie age session only
CSRF_COOKIE_AGE = 3600
CSRF_USE_SESSIONS = False
CSRF_COOKIE_SAMESITE = "Strict"
CSRF_COOKIE_PATH = '/'
CodeThlete
I was only aware of the csrftoken, wasn't aware of the csrfmiddlewaretoken
Santoshi
Is there anyone who has created a elearning platform with django
Doragonsureiyā
Is there anyone who has created a elearning platform with django
Please don't ask meta questions like:
- Any user of $x here?
- Anyone used technology $y?
- Hello, I need help on $z!
Just ask about your problem directly! If you don't know what to ask, please read: http://catb.org/~esr/faqs/smart-questions.html
Ako
Could someone help me solve this problem?
In my models, the primary key is named id.
I would like the paths in the Swagger documentation generated by drf-spectacular to appear like this:
/api/tasks/cards/{card_id}/comments/{comment_id}/
/api/tasks/cards/{card_id}/change-order
instead of:
/api/tasks/cards/{id}/comments/{id}/
/api/tasks/cards/{id}/change-order
I managed to solve this by using lookup_field and overriding get_object.
However, I get warnings:
Warning [CardViewSet]: could not derive type of path parameter "card_id" because model "tasks.models.card.Card" contained no such field. Consider annotating parameter with @extend_schema. Defaulting to "string".
An important point is that I want to keep the primary key name as id, but display card_id in Swagger.
I could get rid of the warnings by specifying parameters for each method, but I feel like I'm doing something wrong.
Кит
Allexiusw
奈姆
Could someone help me solve this problem?
In my models, the primary key is named id.
I would like the paths in the Swagger documentation generated by drf-spectacular to appear like this:
/api/tasks/cards/{card_id}/comments/{comment_id}/
/api/tasks/cards/{card_id}/change-order
instead of:
/api/tasks/cards/{id}/comments/{id}/
/api/tasks/cards/{id}/change-order
I managed to solve this by using lookup_field and overriding get_object.
However, I get warnings:
Warning [CardViewSet]: could not derive type of path parameter "card_id" because model "tasks.models.card.Card" contained no such field. Consider annotating parameter with @extend_schema. Defaulting to "string".
An important point is that I want to keep the primary key name as id, but display card_id in Swagger.
I could get rid of the warnings by specifying parameters for each method, but I feel like I'm doing something wrong.
try this?
@extend_schema(
parameters=[
OpenApiParameter("card_id", OpenApiTypes.NUMBER, OpenApiParameter.PATH),
OpenApiParameter("comment_id", OpenApiTypes.NUMBER, OpenApiParameter.PATH),
]
)
def retrieve(self, request, pk, *args, **kwargs): ...