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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:01:08+00:00 2026-05-15T06:01:08+00:00

I am having trouble getting my model manager to behave correctly when using the

  • 0

I am having trouble getting my model manager to behave correctly when using the Admin interface. Basically, I have two models:

class Employee(models.Model):
    objects = models.EmployeeManager()
    username = models.CharField(max_length=45, primary_key=True)
    . . .

class Eotm(models.Model): #Employee of the Month
    date = models.DateField()
    employee = models.ForeignKey(Employee)
    . . .

And I have an EmployeeManager class that overrides the get() method, something like this:

class EmployeeManager(models.Manager):
    use_for_related_fields = True

    def get(self, *arguments, **keywords):
        try:
            return super(EmployeeManager, self).get(*arguments, **keywords)
        except self.model.DoesNotExist:
            #If there is no Employee matching query, try an LDAP lookup and create
            #a model instance for the result, if there is one.

Basically, the idea is to have Employee objects automatically created from the information in Active Directory if they don’t already exist in the database. This works well from my application code, but when I tried to create a Django admin page for the Eotm model, things weren’t so nice. I replaced the default widget for ForeignKey fields with a TextInput widget so users could type a username (since username is the primary key). In theory, this should call EmployeeManager.get(username='whatever'), which would either return an Employee just like the default manager or create one and return it if one didn’t already exist. The problem is, my manager is not being used.

I can’t find anything in the Django documentation about using custom Manager classes and the Admin site, aside from the generic manager documentation. I did find a blog entry that talked about specifying a custom manager for ModelAdmin classes, but that doesn’t really help because I don’t want to change the model represented by a ModelAdmin class, but one to which it is related.

  • 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-15T06:01:09+00:00Added an answer on May 15, 2026 at 6:01 am

    I may not be understanding what you’re trying to do here, but you could use a custom Form for your Eotm model:

    #admin.py
    from forms import EotmAdminForm
    
    class EotmAdmin(models.ModelAdmin):
        form = EotmAdminForm
    
    
    #forms.py
    from django import forms
    from models import Eotm, Employee
    
    class EotmAdminForm(forms.ModelForm)
        class Meta:
            model = Eotm
    
        def clean_employee(self):
            username = self.cleaned_data['employee']
            return Employee.get(username=username)
    

    That, in theory, should work. I haven’t tested it.

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

Sidebar

Related Questions

I have two models with managers: Category and Project. class PopulatedCategoriesManager(models.Manager): def get_query_set(self): return
I'm using kohana 3.2. and I'm having some trouble getting this new model to
I'm having trouble getting ThinkingSphinx to recognize my conditions. My Discussion model includes the
I am having trouble getting my modal view controllers to display properly. I have
Im having trouble getting my JTable that im using to display either check boxes
I'm having trouble getting Tire working using ElasticSearch with the Bonsai addon on the
I'm currently having trouble getting example code for using tweepy to access Twitter's Streaming
I'm having trouble getting Japanese text to display properly on a website compiled using
I have a exceedingly simplistic data model (below). I am having trouble figuring out
I'm having trouble getting the results of a has_many query using php idiorm/paris. Following

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.