It's perfectly clear and precisely what an ORM is for.

If you don't have an answer, just say so, though I suspect the answer is
use SubQuery.

It is not "useless" in general (obviously if you want to display/ deliver
to an end user,  you need to pluck from the database).  It is useless in
the case I am asking about.



Le jeu. 21 mars 2019 3:22 p.m., Derek <[email protected]> a écrit :

> Your use case is not very clear.
>
> If you are simply "running a few trivial calculations and storing the
> info" then you could use a function in the database to do this for you -
> pulling data directly from Table A and storing the result in Table B. Data
> in Table B could then be later edited using the usual Django functionality.
>
> As a  side note: a trip to the database to get data is not "useless" if
> you need that data for some reason and it is not already present in your
> app.
>
> On Thu, 21 Mar 2019 at 19:06, Dylan Young <[email protected]>
> wrote:
>
>> For example using made-up syntax:
>>
>> Entry.objects.create(start=F(Recurrence.objects.filter(pk=r_id),
>> 'start_time'))
>>
>> Note that we can't use `get` since the whole point is to avoid all the
>> useless round-trips to the DB.
>>
>> Best,
>>
>> Casey
>>
>> On Thu, 21 Mar 2019 at 13:18, Dylan Young <[email protected]>
>> wrote:
>>
>>> It's not a recalculation. It's instantiation.
>>>
>>> Instance data diverges from the factory data and needs to be
>>> independently editable.
>>>
>>> Best,
>>>
>>> Casey
>>>
>>> Le jeu. 21 mars 2019 2:52 a.m., Derek <[email protected]> a écrit :
>>>
>>>> Permanently storing data that can be recalculated from existing data is
>>>> a practice specific to the needs of particular applications.
>>>>
>>>> Have you perhaps considered making use of the "view" table
>>>> functionality available in most databases?
>>>>
>>>> For example, in PostgreSQL you can create a materialized view which
>>>> "caches the result of a complex expensive query and then allow you to
>>>> refresh this result periodically." - see
>>>> http://www.postgresqltutorial.com/postgresql-materialized-views/
>>>>
>>>>
>>>> On Tuesday, 19 March 2019 17:34:11 UTC+2, Dylan Young wrote:
>>>>>
>>>>> Hey all:
>>>>>
>>>>> I often find myself fetching data from models in the database only to
>>>>> run a few trivial calculations and store the info in a different model.
>>>>>
>>>>> Is there an established ORM pattern for directly creating objects in
>>>>> the DB based on the fields of other models?
>>>>>
>>>>> Sorry if this is obvious, but I couldn't find much on this in my web
>>>>> searching.
>>>>>
>>>>>
>>>>> Best,
>>>>>
>>>>> Casey
>>>>>
>>>> --
>>>> 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 [email protected].
>>>> To post to this group, send email to [email protected].
>>>> 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/a1c55adc-c5fa-465c-8740-3a741bc22686%40googlegroups.com
>>>> <https://groups.google.com/d/msgid/django-users/a1c55adc-c5fa-465c-8740-3a741bc22686%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/RDU_KsRqd90/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> To post to this group, send email to [email protected].
>> 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/CAPGJNu40H%3Du5bLLUYYosHpKNDsH7xMFPg-7GU%2B_fHCV59SknyA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAPGJNu40H%3Du5bLLUYYosHpKNDsH7xMFPg-7GU%2B_fHCV59SknyA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/CAF1Wu3NkZCsU8oxLnuGPBtkWpPnq_L_H-o2dVb1rMUjm0pdW3A%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAF1Wu3NkZCsU8oxLnuGPBtkWpPnq_L_H-o2dVb1rMUjm0pdW3A%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> 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 [email protected].
To post to this group, send email to [email protected].
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/CAPGJNu7_qkrcDUG53%3DBvAOFS0RjiJ7Y6o40MhbnHmFcU2w589w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to