Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6384527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:47:13+00:00 2026-05-25T02:47:13+00:00

I have two tables: class Advertisement(models.Model): created_at = models.DateTimeField(auto_now_add=True) author_email = models.EmailField() class Verification(models.Model):

  • 0

I have two tables:

class Advertisement(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    author_email = models.EmailField()

class Verification(models.Model):
    advertisement = models.ForeignKeyField(Advertisement)
    key = models.CharField(max_length=32)

And I need to auto populate Verification table after adding new advertisement.

def gen_key(sender, instance, created, **kwargs):
    if created:
        from hashlib import md5
        vkey = md5("%s%s" % (instance.author_email, instance.created_at))
        ver = Verification(advertisement=instance)
        ver.key = vkey
        ver.save()

post_save.connect(gen_key, sender=Advertisement)

Of course it doesn’t work. Django 1.2
Q: How should I do it?


Ok, halfly solved.
The problem is that post_save() for parent model doesn’t calling for childs models.
So you can solve it by providing child class directly.

class Advertisement(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    author_email = models.EmailField()

class Sale(Advertisement):
    rooms = models.IntegerField(max_length=1)
    subway = models.ForeignKey(Subway)

class Verification(models.Model):
    advertisement = models.ForeignKeyField(Advertisement)
    key = models.CharField(max_length=32)

def gen_key(sender, instance, created, **kwargs):
    code goes here
post_save.connect(gen_key, sender=Sale, dispatch_uid="my_unique_identifier")

So next question is “How can I use parent class for post_save()?”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:47:14+00:00Added an answer on May 25, 2026 at 2:47 am

    instead of connecting to a specific sender, just connect to post_save in general and check the class of the saved instance in your handler eg

    def gen_key(sender, **kwargs):
        if issubclass(sender, Advertisement):
            code goes here
    post_save.connect(gen_key, dispatch_uid="my_unique_identifier")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, one Company and one Employee: class Company(models.Model): name = models.CharField(max_length=60)
I have two tables like so: class Collection(models.Model): name = models.CharField() class Image(models.Model): name
I have two tables (tbArea, tbPost) that relate to the following classes. class Area
On a single page, I have two tables. Each of them has a class
I have two tables Items and ItemDescriptions class Item(Base): __tablename__ = item id =
I have two tables. With Sqlalchemy, I map them to two classes: class A(base):
I'm using EF4.1 POCO. I have two tables [Table(Parent)] public class Parent { public
I am new to entity framework. I have two tables... public class S7_Baskets {
Let's say we have two tables with a many-to-many relationship: public class Left{ /**/
Lets say I have two tables. class CreateUsers < ActiveRecord::Migration def self.up create_table :users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.