Opened 5 years ago

Closed 5 years ago

#30710 closed Uncategorized (wontfix)

impossible without workarounds to see which fields changed when subscribing to signals from generic views

Reported by: MaxR Owned by: nobody
Component: Uncategorized Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

for example I have simple generic view:

#views.py
class CollectorUpdate(generic.UpdateView):
    model = ReportBase
    fields = ['title', 'db', 'additionalPath', 'start_date', 'end_date', 'reportTimestamp',
              'updMethod', 'cronStr', 'code', 'code_renew']
    template_name = 'collector/collector_update_form.html'

and subscribe to post_save signal:

@receiver(signal=signals.post_save, sender=ReportBase)
def runCron(sender, **kwargs):
    """Signal handler. Run cron after post_save signal on """
    collector = kwargs.get('instance')
    updated_fields = kwargs.get('update_fields')

but updated_fields always is None

I think the problem is that in generic.UpdateView into .save() method it is necessary to register a field field_update with interesting for me fields.
As workaround i'm using an instyance of saved object:

 collector = kwargs.get('instance')

but it's looks strange and it is inconvenient. I have to do a lot of extra work

Change History (1)

comment:1 by Carlton Gibson, 5 years ago

Resolution: wontfix
Status: newclosed

This is the expected behaviour (as documented).

As per Specifying which fields to save the saved fields are only limited if you pass update_fields, otherwise it's all, so you don't need it in post_save.

If you want to pass update_fields, override your form's save() accordingly.

Note: See TracTickets for help on using tickets.
Back to Top