Django.fun

Questions & Answers about Django

If an app has multiple models with the same field, whats the best practice for keeping things DRY?

For example, if I have 3 models that look like this: class CallLog(models.Model): lead_id = models.BigIntegerField("Lead ID") # other fields class EmailLog(models.Model): lead_id = models.BigIntegerField("Lead ID") # other fields class TextLog(models.Model): lead_id = models.BigIntegerField("Lead ID") # other fields Do …

Django Admin actions don't work after redefining primary key of the model

I am using standard models.Model in Django. I changed my primary key to _id (mongo). After that, actions in Django Admin don't work anymore. For example, when I use the default Django action – Delete selected, no object is found …

Mon projet s'appellegescard, et lorsque je lance le serveur, j'obtiens cette erreur. Tout le monde sait comment corriger cette erreur [closed]

here we see the error that occurs in my server this is my setting page here we see the url.py page

Cannot understand django user group change signal behavior

I have a function to receive a signal when users change their group. @receiver(signal=m2m_changed, sender=User.groups.through) def save_profile(instance, action, reverse, model, pk_set, using, *args, **kwargs): print(model, instance) When I change the group of the user with username "test" using the …

"DJANGO_SETTINGS_MODULE" bash: syntax error near unexpected token

I wonder why I get this error : django.core.exceptions.ImproperlyConfigured: Passing a 3-tuple to include() is not supported. Pass a 2-tuple containing the list of patterns and app_name, and provide the namespace argument to include() instead. (.venv) this is …

how to using cookies to get data from local storage - DJANGO

i was new in django. i want to get my data back from local storage, but i don't know how to get it. can someone explain me? my application using form NOT MODELS. the application made using django, i use …

Restrict view on utils.py - Django

I've used a tempalte to create a calendar using Django, but now i'm stuck to limit the view of the events on this calendar to just the user who have created the event. I have no model for this calendar, …

Form data is passing in html table

I am submitting the form data by using fetch API and then I want to show some variable values in HTML table. But it's not working as it's supposed to be. I am able to fetch the form data in …

How to retrieve data based on specific field in Django Rest Framework using RetrieveAPIView?

With the code below, I am able to retrieve data based on id, how can I update this code so I can retrieve data based on fileName instead? My urls is urlpatterns = [ path("items/<pk>", SingleUploadItem.as_view()), ] My views …

Django comments deletion

I am having challenges in getting user comment deletion functionality for my django blog. The logic is as follows: user who made a comment under blog post and is logged in will see Delete button next to their comment …

Change boolean data when adding new registration

in this code i want change a boolean data of room when adding new registration For example: when i add new registration in django admin the boolean data of room change to False please can u help in it from …

How to let Kombu consumer return or stream queued message

I am using Kombu and RabbitMq to queue the JPEG image data and stream or return the dequeued message back so it shows the video streaming on the webpage. Kombu consumer detects the message sent from the producer declared in …

Is there a way to display all user last_login and date_joined in django

I want to display all users information on admin dashboard with their last_login and join date I filter user date to display on template data = Profile.objects.filter(Q(user__is_superuser=False), Q(user__is_staff=False)).order_by('-user__last_login')[:10] Profile model user = models.OneToOneField(User,default="1", on_delete=models.CASCADE, related_name="profile") image = …

Как подключить python файл к Django

У меня есть программа на Python которая скачивает видео по ссылке из youtube. Ранее делал на Eel, теперь хочу перейти на Django. Вопрос: как мне получить значение input, checkbox, selectmenu и отправить эти значения в Python функцию, после чего получить …

I am gettitng post method not allowed

from rest_framework.decorators import api_view @api_view(['GET', 'POST']) def contact(request): if request.method == 'GET': contact = ContactMe.objects.all() serializer = ContactMeSerializer(contact, many=True) return JsonResponse(serializer.data, safe=True) elif request.method == 'POST': data = JSONParser().parse(request) serializer = ContactMeSerializer(data=data) if serializer.is_valid(): serializer.save() return JsonResponse(serializer.data, status=201) return JsonResponse(serializer.data, …

showing date from db in html date in django

How can i show date from db in django html template with input type date. As You can see if we use input type 'date'. we can see the below widget showing in html. But if i want …

Add template variable into URL and satisfy reverse match

I found a way to inject variables into the URL per Django Template: Add Variable Into URL As Parameter, but my reverse match is not working. Do I need to use re-path and use regular expressions? Current url.py …

Django Form "'ForwardManyToOneDescriptor' object has no attribute 'all'"

Hey so I'm having quite some problems. In effect trying to add a form to a home-page with options for a user to select based on a DB object. Then once submitted the page will refresh, and the form can …

How to compare model fields using Django-filter package

I am trying to compare two model fields ma8, ma21 using Django-filter but I am not sure where to start. I think I should use F objects like in this answer: How to create a Django queryset filter comparing …

Provide initial data for Django models from txt file

I have a .txt file with 3 columns (longitude, latitude, distance) and 40 million rows. These are the first lines of the file. -179.98 89.98 712.935 -179.94 89.98 712.934 -179.9 89.98 712.933 -179.86 89.98 712.932 -179.82 …

1 2 3 1603 1604