Re: How to get names of columns from QuerySet without executing it

2020-07-06 Thread Eugene Kulak
Michael, this will not work for cases with `values` and `annotations`

On Sunday, July 5, 2020 at 2:23:03 PM UTC-4, michaelfladischer wrote:
>
> What about introspecting the model associated with the QuerySet: 
>
> qs = SomeModel.objects.all() 
> columns = [f.column for f in qs.model._meta.fields] 
>
> Regards, Michael 
>
>
> Am 04.07.2020 um 22:11 schrieb Eugene Kulak: 
> > How to get names of columns from QuerySet without executing it? 
> > If it is not possible what would be the most easier way to execute a 
> > lighter version of the query. 
> > The query itself is unknown, it could be anything. 
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5d260888-c607-4121-81b2-a18215d38f8do%40googlegroups.com.


Re: How to get names of columns from QuerySet without executing it

2020-07-04 Thread Eugene Kulak
The closes I can get with this is the following:

comp = queryset.query.get_compiler(DEFAULT_DB_ALIAS)
fields = [alias or sql.split('.')[1] for _, (sql, _), alias in 
comp.get_select()[0]]


On Saturday, July 4, 2020 at 4:11:41 PM UTC-4, Eugene Kulak wrote:
>
> How to get names of columns from QuerySet without executing it?
> If it is not possible what would be the most easier way to execute a 
> lighter version of the query. 
> The query itself is unknown, it could be anything.
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/46698def-fab7-492a-bbd5-a8190b947aa2o%40googlegroups.com.


Re: How to get names of columns from QuerySet without executing it

2020-07-04 Thread Eugene Kulak
I think reading the question first and answer only when you have anything 
to say is even better?

On Saturday, July 4, 2020 at 5:08:04 PM UTC-4, Vishesh Mangla wrote:
>
> I think learning some sql commands would be good. Lots of youtube tuts 
> available online. 
> https://docs.djangoproject.com/en/3.0/topics/db/sql/#executing-custom-sql-directly
>
> On Sun, Jul 5, 2020 at 1:59 AM Akinfolarin Stephen  > wrote:
>
>> you can filter out the column you want by using 
>> [name of model].objects.get(filter=[name of the column you want])
>>
>> On Sun, Jul 5, 2020 at 10:12 AM Eugene Kulak > > wrote:
>>
>>> How to get names of columns from QuerySet without executing it?
>>> If it is not possible what would be the most easier way to execute a 
>>> lighter version of the query. 
>>> The query itself is unknown, it could be anything.
>>>
>>> -- 
>>> 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...@googlegroups.com .
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/60c63ddd-80fa-44c5-9a8e-10091e307099o%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/django-users/60c63ddd-80fa-44c5-9a8e-10091e307099o%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAFujGLyz6U%3D4t3RSiiAzOo5jkXiCc7bcvzYYyD4do3R-fgbdoQ%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/django-users/CAFujGLyz6U%3D4t3RSiiAzOo5jkXiCc7bcvzYYyD4do3R-fgbdoQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ca3d2a39-1a84-4e85-bc47-c5afa8aebbf8o%40googlegroups.com.


Re: How to get names of columns from QuerySet without executing it

2020-07-04 Thread Eugene Kulak
Thank you, Stephen, but this is not what I asked. I can't change QuerySet 
and I don't know how it looks like.

On Saturday, July 4, 2020 at 4:30:40 PM UTC-4, Akinfolarin Stephen wrote:
>
> you can filter out the column you want by using 
> [name of model].objects.get(filter=[name of the column you want])
>
> On Sun, Jul 5, 2020 at 10:12 AM Eugene Kulak  > wrote:
>
>> How to get names of columns from QuerySet without executing it?
>> If it is not possible what would be the most easier way to execute a 
>> lighter version of the query. 
>> The query itself is unknown, it could be anything.
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/60c63ddd-80fa-44c5-9a8e-10091e307099o%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/60c63ddd-80fa-44c5-9a8e-10091e307099o%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4803a8d6-71bd-4fcf-80fb-35aa504db74bo%40googlegroups.com.


How to get names of columns from QuerySet without executing it

2020-07-04 Thread Eugene Kulak
How to get names of columns from QuerySet without executing it?
If it is not possible what would be the most easier way to execute a 
lighter version of the query. 
The query itself is unknown, it could be anything.

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/60c63ddd-80fa-44c5-9a8e-10091e307099o%40googlegroups.com.


Re: Proxy User and AUTH_USER_MODEL: TypeError: MyUser cannot proxy the swapped model 'myapp.MyUser'.

2020-06-22 Thread Eugene Kulak
It is not clear why it is not possible and what is the rationale behind 
this limitation? I see a lot of questions about this error. Perhaps a nice 
receipt what to do instead could help. For my understanding using the Proxy 
model as Custom User Model is most natural way to override some User's 
methods (like set password, etc)... Importing my custom model instead is 
not an option, as the User model used in Admin and standard views.

Thanks,

On Sunday, April 15, 2018 at 10:10:58 PM UTC-3, Tim Graham wrote:
>
> The behavior seems expected. 
> https://docs.djangoproject.com/en/dev/topics/auth/customizing/#custom-users-and-proxy-models
>
> It looks like if you use a proxy model, then you should import it where 
> needed rather than use AUTH_USER_MODEL.
>
> On Saturday, April 14, 2018 at 6:34:59 PM UTC-4, Nicolas Pantel wrote:
>>
>> Hi,
>>
>> I need help on the topic: Proxy for User model referenced as 
>> AUTH_USER_MODEL.
>>
>> As stated in the doc, needing to add some methods to User model, I tried 
>> to make a 'proxy' model.
>>
>> I made a 'from scratch app', with only a MyUser(User) model, and 
>> AUTH_USER_MODEL = 'myapp.MyUser' in settings.py
>> MyUser has only 'class Meta: proxy = True'
>>
>> On a ./manage.py shell (for example), I have the following traceback:
>>
>> Traceback (most recent call last):
>>>   File "./manage.py", line 22, in 
>>> execute_from_command_line(sys.argv)
>>>   File 
>>> "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py",
>>>  line 363, in execute_from_command_line
>>> utility.execute()
>>>   File 
>>> "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py",
>>>  line 337, in execute
>>> django.setup()
>>>   File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 
>>> 27, in setup
>>> apps.populate(settings.INSTALLED_APPS)
>>>   File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", 
>>> line 108, in populate
>>> app_config.import_models()
>>>   File "/usr/local/lib/python3.6/dist-packages/django/apps/config.py", line 
>>> 202, in import_models
>>> self.models_module = import_module(models_module_name)
>>>   File "/usr/lib/python3.6/importlib/__init__.py", line 126, in 
>>> import_module
>>> return _bootstrap._gcd_import(name[level:], package, level)
>>>   File "", line 978, in _gcd_import
>>>   File "", line 961, in _find_and_load
>>>   File "", line 950, in _find_and_load_unlocked
>>>   File "", line 655, in _load_unlocked
>>>   File "", line 678, in exec_module
>>>   File "", line 205, in 
>>> _call_with_frames_removed
>>>   File "/home/npantel/proxy_user/proxy_user/models.py", line 4, in 
>>> class MyUser(User):
>>>   File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", 
>>> line 158, in __new__
>>> raise TypeError("%s cannot proxy the swapped model '%s'." % (name, 
>>> base_meta.swapped))
>>> TypeError: MyUser cannot proxy the swapped model 'proxy_user.MyUser'.
>>>
>>>
>> Anybody already tried to use proxy on User model?
>>
>> Thanks,
>> Nicolas Pantel
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9c22f6fd-8dfe-4798-929f-d28e17ed8589o%40googlegroups.com.