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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:46:36+00:00 2026-06-09T20:46:36+00:00

I have a requirement to write a DB row when a user logs in.

  • 0

I have a requirement to write a DB row when a user logs in. The following code is in models.py (at end of file, after model definitions);

models.py

from django.contrib.auth.signals import user_logged_in
from utils import *
def rec_login(sender, request, user, **kwargs):
    u_audit('some text here', user)    

user_logged_in.connect(rec_login)

There’s a utilities module which is imported in modules.py. The following code is called in utils.py from the above function;

utils.py

from app.models import *
def u_audit(msg,u):
    ua=UserLog(action=msg, user=u, actiontime=datetime.now())
    ua.save()

I’m reusing the u_audit() function in several other places (post-login).

When a user logs in, I get a NameError for the UserLog object (i.e. it looks like the model definitions can’t be accessed by the signal callback function).

The UserLog object referred to above is just a simple models.Model.

Anyone know what I’m missing?

I’ve tried putting a simple file write in the callback function in models.py and tried the same thing in the u_audit() function. instead and that works fine, so I know it’s being called properly. I’ve got other signal callback functions registered (all post-login) and they’re using models and working fine.

  • 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-06-09T20:46:38+00:00Added an answer on June 9, 2026 at 8:46 pm

    Not a circular import? Utils refers to models and models to utils – it will not work. Please change utils.py to:

    def u_audit(msg,u):
        from app.models import UserLog
        ua=UserLog(action=msg, user=u, actiontime=datetime.now())
        ua.save()
    

    But also something like that suggest that maybe models.py is good place for u_audit and you should just move it there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement to write HTML to the file system and I was
We have a requirement to parse a file and write the data to an
I have a requirement to take the test data from Excel sheet and write
I have different requirement from a customer to write a automated test script for
We have a requirement to fetch information from the following API http://www.viralheat.com/developer/sentiment_api#method1 which can
I have a requirement to write to a log file on reception of any
I have a requirenment to write to a file rather than in System.out.println and
I have requirement as following like showing ABPeoplePickerNavigationController in tabbar based application. I researched
I have a requirement to write a stored procedure that accepts a start date,
I have a requirement to log to different log file using Nlog based different

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.