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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:22:02+00:00 2026-05-21T00:22:02+00:00

I have a model that I want staff to be able to edit up

  • 0

I have a model that I want staff to be able to edit up to the date for the event. Like this:

class ThingAdmin(admin.ModelAdmin):
    model = Thing

    if obj.date < today: #Something like that
        inlines = [MyInline,]

The problem is, I don’t have access to the obj instance at this level. I’ve tried overriding get_formset(), but didn’t get anywhere.

Please advise?

  • 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-21T00:22:03+00:00Added an answer on May 21, 2026 at 12:22 am

    Thanks to the comments for a change in 1.4. My implementation here wasn’t thread safe either, so it really should have been deleted.

    Since get_formsets is passed the object and calls get_inline_instances, we can modify both functions to act on the object.

    This should work:

    class ThingAdmin(admin.ModelAdmin):
        model = Thing
    
        inlines = [inline]
        other_set_of_inlines = [other_inline]
    
        def get_inline_instances(self, request, obj=None):
            #                                    ^^^ this is new
            inline_instances = []
    
            if obj.date > datetime.date(2012, 1, 1):
                inlines = self.inlines
            else:
                inlines = self.other_set_of_inlines
    
            for inline_class in inlines:
                inline = inline_class(self.model, self.admin_site)
                if request:
                    if not (inline.has_add_permission(request) or
                            inline.has_change_permission(request) or
                            inline.has_delete_permission(request)):
                        continue
                    if not inline.has_add_permission(request):
                        inline.max_num = 0
                inline_instances.append(inline)
            return inline_instances
    
        def get_formsets(self, request, obj=None):
            for inline in self.get_inline_instances(request, obj):
                #                                           ^^^^^ this is new
                yield inline.get_formset(request, obj)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that is something like this: class Input(models.Model): details = models.CharField(max_length=1000)
I want to have a model with calculated fields that I can apply sorting
Right now, I have more than 25 vertices that form a model. I want
I have a model that holds user address. This model has to have first_name
So I am creating a website that I want to have an admin directory
I want to be able to have methods in a module that are not
Hay I have a model like this def Photo(models.Model): # Photo object fields... def
If I'm building an application that will have over 30 models, and I want
I have a model that has a ForeignKey to the built-in user model in
I have a model that uses a acts_as_nested_set fork, and I've added a method

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.