Saturday, 15 September 2012

python - Do Some work before Saving and After Saving data in django Admin -


I have a model class 'newsletters' in which there is no option to send students, teachers etc.

I want to receive all the emails of the user or the teacher, even after the button is pressed, get the saved ID currently, the newsletter and the selected choice, all the emails of the student or teacher, Can save in another table.

All this is done on the admin panel of the DJ.

  class newsletter (models.model): newsletter_id = model.autofield (primary_key = true) topic = model.read field (max_long = 512) content = rich textfield () send_to_choice = {('0 ',' None '), (' 1 ',' student '), (' 2 ',' teacher ')} send_to = model Built-in = Model  

When admin is selected, the date time filters (auto_now_add = true) created_by = Models.EmailField (max_length = 254) updated_on = models.DateTimeField (auto_now_add = true) updated_by = models.EmailField (max_length = 254) One option should be enabled in a query and all emails will be shown for the selected option. I know that the question is, but it did not know how it was implemented on the Dinggo Admin Panel.

UPDATED:

I have written this simple task to test that if it is executed then I have to reason on it. Obj.send_to == '1': messages.success (request, 'if you do not change: obj.save) MyMold saved !! ') Obj.created_by =' abc@gmail.com 'if obj.send_to ==' 1 ': messages.success (Request,' MyModel was saved! ') Obj.created_by =' Abc@gmail.com 'obj.save ()

You must override the method:

  Class NewsletterAdammin (AdminModelAdammin): def save_model (auto, request, obj, form, change): obj.save () if it does not change: #New built newsletter If obj Send_to == '1': For the student. Bob .: (): EmailLog.objects.create (St. Udent = student, newsletter = obje) elif obj.send_to == '2': For teacher for teacher. Objects.all (): EmailLog.objects.create (teacher = teacher, newsletter = obj)  

No comments:

Post a Comment