For a light version of the query, you can try a qs.first() as Django will
limit the SQL request to the first element.
On Saturday, July 4, 2020 at 10:11:41 PM UTC+2, Eugene Kulak wrote:
>
> How to get names of columns from QuerySet without executing it?
> If it is not possible what wou
el._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 quer
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
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
, 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 it
[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.
>
he 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 mos
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
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
9 matches
Mail list logo