Re: Pagination breaks in ListView after migrating from Django 1.11 to 2.2 with SQLite

2019-04-24 Thread Szabolcs Hodossy
Thanks for the help, I have checked those release notes, but I was not able
to identify the related change (neither subquery nor __in lookup). I wanted
to give you a deeper look into the code, but during that I managed to
isolate the issue. It seems that the '__in' lookups previously accepted
objects and automatically extracted the referenced columns in case of
Foreign Key fields, but that is not valid now. I added `values('id')`
everywhere, and it solved the problem. I am not sure how to feel about this
change, as 'id' is automatically created.

Br,
Szabolcs

On Tue, Apr 23, 2019 at 4:39 PM Simon Charette  wrote:

> I assume you are either using a Subquery annotation that returns
> multiple results or an __in lookup against a query with multiple columns.
>
> I vaguely remember something changed in this area but it was documented
> in one of the 2.0, 2.1 or 2.2 release notes.
>
> Best,
> Simon
>
> Le mardi 23 avril 2019 10:31:43 UTC-4, hodossy...@gmail.com a écrit :
>>
>> Hello,
>>
>> I am facing the following issue after upgrading to 2.2 from 1.11. Here is
>> the stack trace:
>>
>> Traceback (most recent call last):
>>   File "(...)\.env\lib\site-packages\django\db\backends\utils.py", line
>> 84, in _execute
>> return self.cursor.execute(sql, params)
>>   File "(...)\.env\lib\site-packages\django\db\backends\sqlite3\base.py",
>> line 383, in execute
>> return Database.Cursor.execute(self, query, params)
>> sqlite3.OperationalError: only a single result allowed for a SELECT that
>> is part of an expression
>>
>> The above exception was the direct cause of the following exception:
>>
>> Traceback (most recent call last):
>>   File "(...)\dashboard\deployment\tests\test_view.py", line 53, in
>> test_display_list_view
>> response = self.client.get(self.url_my_list)
>>   File "(...)\.env\lib\site-packages\django\test\client.py", line 535, in
>> get
>> response = super().get(path, data=data, secure=secure, **extra)
>>   File "(...)\.env\lib\site-packages\django\test\client.py", line 347, in
>> get
>> **extra,
>>   File "(...)\.env\lib\site-packages\django\test\client.py", line 422, in
>> generic
>> return self.request(**r)
>>   File "(...)\.env\lib\site-packages\django\test\client.py", line 503, in
>> request
>> raise exc_value
>>   File "(...)\.env\lib\site-packages\django\core\handlers\exception.py",
>> line 34, in inner
>> response = get_response(request)
>>   File "(...)\.env\lib\site-packages\django\core\handlers\base.py", line
>> 115, in _get_response
>> response = self.process_exception_by_middleware(e, request)
>>   File "(...)\.env\lib\site-packages\django\core\handlers\base.py", line
>> 113, in _get_response
>> response = wrapped_callback(request, *callback_args,
>> **callback_kwargs)
>>   File "(...)\.env\lib\site-packages\django\views\generic\base.py", line
>> 71, in view
>> return self.dispatch(request, *args, **kwargs)
>>   File "(...)\.env\lib\site-packages\django\contrib\auth\mixins.py", line
>> 52, in dispatch
>> return super().dispatch(request, *args, **kwargs)
>>   File "(...)\.env\lib\site-packages\django\views\generic\base.py", line
>> 97, in dispatch
>> return handler(request, *args, **kwargs)
>>   File "(...)\.env\lib\site-packages\django\views\generic\list.py", line
>> 157, in get
>> context = self.get_context_data()
>>   File "(...)\dashboard\deployment\views.py", line 53, in get_context_data
>> context = super().get_context_data(**kwargs)
>>   File "(...)\.env\lib\site-packages\django\views\generic\list.py", line
>> 119, in get_context_data
>> paginator, page, queryset, is_paginated =
>> self.paginate_queryset(queryset, page_size)
>>   File "(...)\.env\lib\site-packages\django\views\generic\list.py", line
>> 69, in paginate_queryset
>> page = paginator.page(page_number)
>>   File "(...)\.env\lib\site-packages\django\core\paginator.py", line 70,
>> in page
>> number = self.validate_number(number)
>>   File "(...)\.env\lib\site-packages\django\core\paginator.py", line 48,
>> in validate_number
>> if number > self.num_pages:
>>   File "(...)\.env\lib\site-packages\django\utils\functional.py", line
>> 80, in __get__
>> res = instance.__dict__[self.name] = self.func(instance)
>>   File "(...)\.env\lib\site-packages\django\core\paginator.py", line 97,
>> in num_pages
>> if self.count == 0 and not self.allow_empty_first_page:
>>   File "(...)\.env\lib\site-packages\django\utils\functional.py", line
>> 80, in __get__
>> res = instance.__dict__[self.name] = self.func(instance)
>>   *File "(...)\.env\lib\site-packages\django\core\paginator.py", line
>> 91, in count*
>> *return c()*
>>   File "(...)\.env\lib\site-packages\django\db\models\query.py", line
>> 392, in count
>> return self.query.get_count(using=self.db)
>>   File "(...)\.env\lib\site-packages\django\db\models\sql\query.py", line
>> 504, in get_count
>> number = obj.get_aggregation(using, ['__count'])['__count']
>>   File "(...)\.env\li

Re: Different database types use in a single Django project

2019-05-10 Thread Szabolcs Hodossy
Hi Bbake,

You can also use a multi DB setup
 (I suggest
routers), and follow this guide to integrate a Mongo backend:
https://medium.freecodecamp.org/using-django-with-mongodb-by-adding-just-one-line-of-code-c386a298e179

One drawback that you lose relationships across DBs, but I think you
already prepared for that.

Hope this helps,
Szabolcs

On Fri, May 10, 2019 at 2:10 PM Chetan Ganji  wrote:

> Hi Bbake,
>
> Django Class Based Views and Models are wired for relational databases
> only. If you want to use MongoDB with django you have to say bye bye to CBV
> and Django ORM. There are some third party libraries to map django models
> to mongo, but IDK how good they are for production use.
>
> One way to solve this problem is use Function Based Views for views where
> MongoDB will be used.
> You will have to access mongo db using a database driver like pymongo.
>
> If you just need to store the json data, another way to solve this problem
> is to use django and postgres database.
> PostgreSQL has JSON field, django also supports that. Check the official
> documents for more info.
> https://docs.djangoproject.com/en/2.2/ref/contrib/postgres/fields/
>
> If you find any more solutions, please let me know, as I also want to
> explore the options of using mongo with django.
> Thanks in advance.
>
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji.che...@gmail.com
> http://ryucoder.in
>
>
> On Fri, May 10, 2019 at 5:27 PM Bbake Waikhom  wrote:
>
>> Is there any way that I can use different database type in a single
>> Django project like some model A will use SQL and some model B will use
>> MongoDB? Because in my project some data are better to store in a
>> relational database and some are better to store in a NoSQL database. I've
>> been searching for a while to achieve this but I couldn't find any
>> solution. Please let me know if there is a way. Thank you.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/b3776d83-18c9-47a0-9a8a-e3e7cb2e849a%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMKMUjvwPcizHF%3DRrdJai9j8C2BakWj7XpMMK_O%2BbntuByHrTw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFp9oi9ZCeLQWQu6hmXvJdy%3Df6KWhDTQuaS79SrP45U%2Bo1ToCA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.