django-views

Postgre SQL ignore the filtering condition if the value is null

会有一股神秘感。 提交于 2021-01-04 08:03:06
问题 I have the following three variables passed to the query A,B and C . A, B and C can take any values including null. When I run the below queryset, it should ignore the condition if the value in A,B or C is null queryset = User.objects.values().filter(A_name=A, B_name=B, C_name =C) For example, if C value passed in null then the query should behave like queryset = User.objects.values().filter(A_name=A, B_name=B) And if C and A value passed in null then the query should behave like queryset =

python/django: model object has no attribute 'prefetch_related'

青春壹個敷衍的年華 提交于 2021-01-03 06:50:25
问题 I have created a model 'VehicleDetails' in which a user can fill the details of a vehicle and another model 'TripStatus' in which he updates the vehicle location. I wanted to get the latest location for which i did as in my below code. I use prefetch_related in my view to returns the location values for a particular vehicle. But, when after running the server, it raises an error : "TripStatus object has no attribute 'prefetch_related'". I would appreciate helping me solve this. models.py:

django csrf_token in search result url

喜你入骨 提交于 2021-01-02 05:50:53
问题 Have csrf in search result url. Don't know why is there and how to remove it. Search works nice. Here is URL /search/?csrfmiddlewaretoken=675d1340034e094866d15a921407e3fc&q=testing here is view: def search(request): query = request.GET.get('q', '') rezult = [] if query: qset1 = ( Q(title__icontains=query) ) result = Product.objects.filter(qset1).distinct() if result.count() == 1: return HttpResponseRedirect(result[0].get_absolute_url()) return render_to_response('search/search.html',{'query':

django csrf_token in search result url

允我心安 提交于 2021-01-02 05:50:37
问题 Have csrf in search result url. Don't know why is there and how to remove it. Search works nice. Here is URL /search/?csrfmiddlewaretoken=675d1340034e094866d15a921407e3fc&q=testing here is view: def search(request): query = request.GET.get('q', '') rezult = [] if query: qset1 = ( Q(title__icontains=query) ) result = Product.objects.filter(qset1).distinct() if result.count() == 1: return HttpResponseRedirect(result[0].get_absolute_url()) return render_to_response('search/search.html',{'query':

Save formset in an UpdateView

泪湿孤枕 提交于 2021-01-01 06:45:06
问题 I have the models Entry and Meaning below with many-to-many relation. I need to create an update form/view to edit Entry and Meaning objects at the same time. I have also to be able to add more Meaning objects to an Entry object while editing it. I tried to use UpdateView and modelformset_factory as below. I can see the forms, but my view doesn't save the Meaning changes. I have two questions: How do I save the Meaning changes? How do I add or delete a Meaning object in this form/view? Models

Django - form_valid() vs save()

眉间皱痕 提交于 2020-12-30 07:40:10
问题 In django forms, for saving other data I usually use form_valid() but as I can also use save() method of formclass. Today I overrided save() instead of form_valid() and I got problem with my manytomanyfield. When using , the values of manytomanyfield are not saved but when I use form_valid() they start saving. Can anybody tell me the reason and what are the differences between both, which is the most convenient method and in what situation? Here is my overriding of save() method: class

How to server HTTP/2 Protocol with django

瘦欲@ 提交于 2020-12-29 06:09:00
问题 I am planing to deploy my django project with HTTP/2 protocol but I unable to find the proper way how can I server my django based website with HTTP/2, the only thing that I find is hyper-h2. I read the documentation but unable to setup the connections. If anybody know how to server django on HTTP/2. 回答1: You can do with Nginx proxy if you have existing nginx config. you do by just adding a word . http2 in listen listen 443 ssl http2 default_server; full document avaliable in https://www

How to server HTTP/2 Protocol with django

 ̄綄美尐妖づ 提交于 2020-12-29 06:07:24
问题 I am planing to deploy my django project with HTTP/2 protocol but I unable to find the proper way how can I server my django based website with HTTP/2, the only thing that I find is hyper-h2. I read the documentation but unable to setup the connections. If anybody know how to server django on HTTP/2. 回答1: You can do with Nginx proxy if you have existing nginx config. you do by just adding a word . http2 in listen listen 443 ssl http2 default_server; full document avaliable in https://www

How to server HTTP/2 Protocol with django

你。 提交于 2020-12-29 06:06:25
问题 I am planing to deploy my django project with HTTP/2 protocol but I unable to find the proper way how can I server my django based website with HTTP/2, the only thing that I find is hyper-h2. I read the documentation but unable to setup the connections. If anybody know how to server django on HTTP/2. 回答1: You can do with Nginx proxy if you have existing nginx config. you do by just adding a word . http2 in listen listen 443 ssl http2 default_server; full document avaliable in https://www

How to server HTTP/2 Protocol with django

丶灬走出姿态 提交于 2020-12-29 06:05:25
问题 I am planing to deploy my django project with HTTP/2 protocol but I unable to find the proper way how can I server my django based website with HTTP/2, the only thing that I find is hyper-h2. I read the documentation but unable to setup the connections. If anybody know how to server django on HTTP/2. 回答1: You can do with Nginx proxy if you have existing nginx config. you do by just adding a word . http2 in listen listen 443 ssl http2 default_server; full document avaliable in https://www