Signals - Need a signal after annotations are added

57 views
Skip to first unread message

Mike Brown

unread,
Feb 23, 2019, 3:08:43 PM2/23/19
to Django developers (Contributions to Django itself)
I have a situation where I need a signal for when a model object is fully instantiated.

Currently, there are signals for pre_init and post_init. However, when post_init is fired, 
the object is not fully 'initialized' in the sense that annotations have not yet been added to the object.


In django.db.models.query there is class ModelIterable(BaseIterable)

In this class there is code to run a query and then apply annotations.

Should there be a new signal added to Django that is fired after the annotations are complete and the object is fully instantiated?

Maybe a signal called 'instantiation_complete'?


Philip James

unread,
Feb 24, 2019, 12:48:17 AM2/24/19
to django-d...@googlegroups.com
Hi! I think I'm misunderstanding what you're asking for. I've looked at every doc I can find on annotations to refresh my memory, and it looks like annotations only apply to query sets, not to objects? Could you say a bit more about your use case to help me grok what's going on?

Thanks,
Philip

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/bc4516df-71da-429f-af80-7c98a60ab91f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Bennett

unread,
Feb 24, 2019, 1:31:29 AM2/24/19
to django-d...@googlegroups.com
On Sat, Feb 23, 2019 at 9:48 PM Philip James <p...@philipjohnjames.com> wrote:
Hi! I think I'm misunderstanding what you're asking for. I've looked at every doc I can find on annotations to refresh my memory, and it looks like annotations only apply to query sets, not to objects? Could you say a bit more about your use case to help me grok what's going on?

When a QuerySet is annotated, each object in the results gets the additional attribute(s) attached to it from the annotation. I think this is a request for a signal that fires after those attributes have been added to the model instances. 

Mike Brown

unread,
Feb 24, 2019, 2:05:00 AM2/24/19
to Django developers (Contributions to Django itself)
 I think this is a request for a signal that fires after those attributes have been added to the model instances. 

Yes.

samarth parashari

unread,
Feb 25, 2019, 7:18:14 AM2/25/19
to django-d...@googlegroups.com
django signal are work like database trigger.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
Reply all
Reply to author
Forward
0 new messages