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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:59:57+00:00 2026-06-11T06:59:57+00:00

I have the form in Django admin with tabular inline: class MemberAdminInline(admin.TabularInline): model =

  • 0

I have the form in Django admin with tabular inline:

class MemberAdminInline(admin.TabularInline):
    model = Member
    fields = ("first_name", "last_name")
    readonly_fields = ("first_name", )

class GroupAdmin(admin.ModelAdmin):
    model = Group
    fields = ("name", "description")
    inlines = [MemberAdminInline]

I would like to display Member’s last_name conditionally. I.e.

"If first_name = "Joe": don't display show field for last_name".

Its important to really not to display field and not hide it (Using JS for example),
because in my real-work scenario in certain cases this field can contain a binary data which gets breaked when passed through form.
I.e.
I want last_name to be editable through admin only for certain first_names.

I’ve tried provide a custom form for inline and conditionally remove field from there, or dynamically include field in list of readonly_fields at various stages, but Django still always tried to find the field I want to hide field.

Django 1.3.1

  • 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-11T06:59:59+00:00Added an answer on June 11, 2026 at 6:59 am

    It seems like Django calculates list of fields for formset at inline creation time and then formset insists on these fields to exist.

    So the only ways to overcome this that I’ve found is to actually ignore saved value when needed:

    class MemberAdminInlineForm(forms.ModelForm):
        def clean_last_name(self):
            if hasattr(self, "instance"):
                if self.instance.first_name == "Joe":
                    return self.instance.last_name
            return self.cleaned_data["last_name"].
    
    class MemberAdminInline(admin.TabularInline):
        model = Member
        fields = ("first_name", "last_name")
        readonly_fields = ("first_name", )
        form = MemberAdminInlineForm
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so I have a custom django admin built from a Author Model: class
I have a Django form that uses a different number of fields based on
I have a Django form that uses an integer field to lookup a model
I have a form like: #forms.py from django import forms class MyForm(forms.Form): title =
I have a form in my Django app (not in admin) that allows staff
I have following setup. from django.db import models from django.contrib.auth.models import User class Event(models.Model):
I have the following model: from django.db import models class State(models.Model): name = models.CharField(max_length=30)
In Django's admin interface, there is a form, of a specific model that I
I have a Date of birth field in my admin form of my django
I have the following model and TabularInline subclasses: class SomeModel(models.Model): name = models.CharField(max_length=50) class

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.