Trigger receiver signal on Proxy model

137 views
Skip to first unread message

Yarnball

unread,
May 12, 2017, 1:23:29 AM5/12/17
to Django users
I'm using a proxy model, so that I can use Elastic search on the same model using two different serialisers.

However, the new_index_elastic function never runs (ie I never see the print, and my NewModel never gets indexed).

How would I do this?

class Item(EsIndexable, models.Model):
    title = models.CharField( blank=True)
    tag = models.ManyToManyField('Tag', blank=True)

    class Elasticsearch(EsIndexable.Elasticsearch):
        serializer_class = ItemEsSerializer
        fields = ['title', 'tag']

@receiver(post_save, sender= Item)
def index_elastic(instance, **kwargs):
    instance.es.do_index()

class Newmodel(Item):
    class Meta:
        proxy = True
    class Elasticsearch(EsIndexable.Elasticsearch):
        serializer_class = NewModelEsSerializer
        fields = ['title', 'tag']

@receiver(post_save, sender= Newmodel)
def new_index_elastic(instance, **kwargs):
    print('Index proxy')
    instance.es.do_index()

Constantine Covtushenko

unread,
May 12, 2017, 3:53:38 PM5/12/17
to django...@googlegroups.com
Hi,

It is supposed to run 'index_elastic' when you save 'Item' entity.
And to run 'new_index_elastic' when you save 'Newmodel' entity.
May be the reason why you do not see proper logs that in your code all operations with entity are done based on 'Item' class?

Hope that helps.

Regards,
Constantine C.


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django...@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/967390f9-5c81-4f0d-8cb5-9c24a9f88466%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Sincerely yours,
Constantine C
Reply all
Reply to author
Forward
0 new messages