leb dev <testd...@gmail.com>: Sep 24 12:16PM -0700
I now how to use django pagination with ORM django after filtering the
required data and put in into *pagination div*
*queryset_list = employee.objects.all()*
*query=request.GET.get("q")*
* if query:*
* queryset_list=queryset_list.filter(*
* Q(name__icontains=query)|*
* Q(father_name__icontains=query)|*
* Q(mother_name__icontains=query)|*
* Q(content__icontains=query)|*
* Q(create_date__icontains=query)*
* # Q(user__first_name__contains=query)*
* ).distinct()*
* paginator = Paginator(queryset_list, 5)*
* page_request_var = "page"*
* page = request.GET.get(page_request_var)*
* queryset = paginator.get_page(page)*
* context={*
* "object_list":queryset,*
* "title":"List Items",*
* "page_request_var":page_request_var,*
* }*
* return render(request,"blog/list.html", context)*
the above code is working
my question is how to convert this ORM into raw SQL
i know that i must use LIMIT and OFFSET in raw SQL to embedded into
paginator.
|
Deep Sukhwani <deepsu...@gmail.com>: Sep 25 06:37AM +0530
Have you tried using the *.query* on Django's QuerySet (documentation: [1])
For example, if my QuerySet is:
*User.objects.filter(username__contains='alpha')*
I can obtain the underlying raw SQL Query using:
*print(User.objects.filter(username__contains='alpha').query)*
*>>> *print(User.objects.filter(username__contains='alpha').query)
SELECT `auth_user`.`id`, `auth_user`.`password`, `auth_user`.`last_login`,
`auth_user`.`is_superuser`, `auth_user`.`username`,
`auth_user`.`first_name`, `auth_user`.`last_name`, `auth_user`.`email`,
`auth_user`.`is_staff`, `auth_user`.`is_active`, `auth_user`.`date_joined`
FROM `auth_user` WHERE `auth_user`.`username` LIKE BINARY %alpha%
1:
https://docs.djangoproject.com/en/2.2/topics/db/sql/#performing-raw-queries
--
Regards
Deep L Sukhwani
|
Larry Martell <larry....@gmail.com>: Sep 24 08:22AM -0400
Anaconda, Enthought, ActiveState, Red Hat and maybe others as well.
Also large companies can do their own support.
|
Deep Sukhwani <deepsu...@gmail.com>: Sep 24 05:59PM +0530
Thanks for the prompt reply. Did a quick cursory check with Anaconda, I
don't think Anaconda does it. In fact Anaconda has posted a few months ago
about Python 2's EOL (End of Life) -
https://www.anaconda.com/end-of-life-eol-for-python-2-7-is-coming-are-you-ready/
Also, just did a quick look at their professional services, couldn't see
anything suggesting they will offer python 2 support beyond the python 2's
community itself.
--
Regards
Deep L Sukhwani
|
Larry Martell <larry....@gmail.com>: Sep 24 08:31AM -0400
You can get anyone to do anything for enough money.
|
Nick Sarbicki <nick.a....@gmail.com>: Sep 24 01:33PM +0100
I'm not convinced anyone could pay me enough to go back to Python 1...
On Tue, Sep 24, 2019 at 1:32 PM Larry Martell <larry....@gmail.com>
wrote:
|
Larry Martell <larry....@gmail.com>: Sep 24 08:40AM -0400
Ha! How about perl? ;-)
|
"Andréas Kühne" <andrea...@hypercode.se>: Sep 24 03:23PM +0200
Yes of course - I think RedHat will be continuing to support a python 2
environment because they haven't updated their own internal infrastructure
and also their distributions to python 3.
However - using one of those is still not very smart. The problem is that
all plugins have moved on. So Django, Flask, Numpy, Scipy, Mypy, Pypy and
so on are ported to python 3. The main argument still stands - why invest
money today into a language that is obsolete - and that you have had
several years notice to stop using? Porting to python 3 isn't that hard
either - there are a lot of tools to help you do that. I myself have ported
a website from python 2 to python 3, with tens of thousands rows of code.
So all you need to do is to set aside time to port the applications - and
if you don't do it now, you WILL need to do it later - that's a simple
fact. And then the code will be in the best case scenario obsolete, worst
case useless. I can't see one reason to invest a cent into writing python 2
code. I know that I am lucky to be able to define what I want to work with
and to set requirements and also have no legacy code. But even having
legacy code, it's just a matter of investing into your own application.
To say that it can't be done - look at Instagram - they did it with their
codebase, and I don't think that many of us are working on that size of
codebase.....
Regards,
Andréas
|
אורי <u...@speedy.net>: Sep 24 04:45PM +0300
On Sat, Sep 21, 2019 at 8:32 PM Ankita Gupta <ankita.g...@gmail.com>
wrote:
> Not related to Django...
Then write to pytho...@python.org
|
Mike Dewhirst <mi...@dewhirst.com.au>: Sep 25 08:59AM +1000
I think the original question was around backwards conversion of 3.x
code to 2.7.
I don't know of course because all my efforts have been forwards but I
believe the six module would be the easiest way backwards.
And I imagine you would simply run your unit tests in 2.7 and use the
six utilities to correct errors. With a little luck that would
simultaneously keep the codebase compatible with 3.x for the inevitable
forward upgrade.
Just a thought
Mike
On 24/09/2019 10:00 pm, Larry Martell wrote:
|
"Huy Bùi" <huybui...@gmail.com>: Sep 24 12:41AM -0700
Hello,
Everytime i try to access a url, the Django developer server auto quit
without any log about what happens.
After debugging a little bit, i find out if i remove this block of code in
the template file, i can access the web page normally:
<select name="department1" class="department">
<option value=""></option>
{% for d in departments %}
<option value="{{ d.id }}"> {{ d.name }} - {{ d.department_code }}
</option>
{% endfor %}
</select>
But i can iterate the QuerySet in the view normally, it seems like there
aren't any problem iterating the QuerySet:
def edit(request):
departments = Department.objects.filter()
for d in departments:
print(d.id, d.name, d.department_code)
return render(request, 'edit/edit.html', {'departments': departments})
I have no idea what is happening and it's driving me crazy. Any help would
be appreciated. Thank you.
|
Deep Sukhwani <deepsu...@gmail.com>: Sep 24 09:29PM +0530
Possible to push the whole code to a Github repo so someone could check out
and try locally - Couldn't really figure out anything that might be going
wrong by looking at this much mode?
Also, just out of curiosity, why are you using *Department.objects.filter()*
instead of *Department.objects.all()* since you are anyways not passing
anything to the filter.
--
Regards
Deep L Sukhwani
|