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 3598828
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:17:28+00:00 2026-05-18T20:17:28+00:00

Am working on an project in which I made an app core it will

  • 0

Am working on an project in which I made an app “core” it will contain some of the reused models across my projects, most of those are polymorphic models (Generic content types) and will be linked to different models.

Example below am trying to create audit model and will be linked to several models which may require auditing.

This is the polls/models.py

from django.db import models
from django.contrib.auth.models import User
from core.models import *
from django.contrib.contenttypes import generic

class Poll(models.Model):
    ## TODO: Document
    question = models.CharField(max_length=300)
    question_slug=models.SlugField(editable=False)
    start_poll_at = models.DateTimeField(null=True)
    end_poll_at = models.DateTimeField(null=True)
    is_active = models.BooleanField(default=True)
    audit_obj=generic.GenericRelation(Audit)
    def __unicode__(self):
        return self.question


class Choice(models.Model):
    ## TODO: Document
    choice = models.CharField(max_length=200)
    poll=models.ForeignKey(Poll)
    audit_obj=generic.GenericRelation(Audit)

class Vote(models.Model):
    ## TODO: Document
    choice=models.ForeignKey(Choice)
    Ip_Address=models.IPAddressField(editable=False)
    vote_at=models.DateTimeField("Vote at", editable=False)

here is the core/modes.py

from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic


class Audit(models.Model):
    ## TODO: Document
    # Polymorphic model using generic relation through DJANGO content type
    created_at = models.DateTimeField("Created at", auto_now_add=True)
    created_by = models.ForeignKey(User, db_column="created_by", related_name="%(app_label)s_%(class)s_y+")
    updated_at = models.DateTimeField("Updated at", auto_now=True)
    updated_by = models.ForeignKey(User, db_column="updated_by", null=True, blank=True,
                                   related_name="%(app_label)s_%(class)s_y+")
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField(unique=True)
    content_object = generic.GenericForeignKey('content_type', 'object_id')

and here is polls/admin.py

from django.core.context_processors import request
from polls.models import Poll, Choice
from core.models import *
from django.contrib import admin

class ChoiceInline(admin.StackedInline):
    model = Choice
    extra = 3

class PollAdmin(admin.ModelAdmin):
    inlines = [ChoiceInline]

admin.site.register(Poll, PollAdmin)

Am quite new to django, what am trying to do here, insert a record in audit when a record is inserted in polls and then update that same record when a record is updated in polls.

  • 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-18T20:17:29+00:00Added an answer on May 18, 2026 at 8:17 pm

    You can override the save() method of Poll model or you can use Django Signals

    to do it.

    try something like:

    def save(self, *args, **kwargs,request):    
         super(ModelName, self).save(*args, **kwargs)
         ## followed by your code
    

    you can save your model instance using

    modelinstance.save(request)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am working on an project in which I made an app core it will
I'm working in a project which needs to clean up some third party XSD
I'm currently working on a project which will support multiple file writing specifications (imagine
I'm working on a project to create a CMS, which will entail importing a
I am working on a school project in which I query and receive some
I'm working on a project which is just about to start, and since I
I am working on a project which uses an import #import progid:Blah.blah.retrieve rename_namespace(Blah) but
I'm working on a project which stores single images and text files in one
I'm working on a project which I'm really not sure how to unit test.
I am working on a project which was developed in Visual Studio 2005 (.NET

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.