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

  • Home
  • SEARCH
  • 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 6105629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:59:30+00:00 2026-05-23T13:59:30+00:00

class Foo(models.Model): title = models.TextField() userid = models.IntegerField() image = models.CharField(max_length=100) def __unicode__(self): return

  • 0
class Foo(models.Model):
    title = models.TextField()
    userid = models.IntegerField()
    image = models.CharField(max_length=100)
    def __unicode__(self):
       return self.title

class Bar(models.Model):
    foo = models.ForeignKey(Foo, related_name='Foo_picks', unique=True)
    added_on = models.DateTimeField(auto_now_add=True)

In Django admin add_view:

def add_view(self, *args, **kwargs):
    self.exclude = ("added_on",)
    self.readonly_fields = ()
    return super(Bar, self).add_view(*args, **kwargs)

So, Field shows in the admin add view is foo Which is a drop down list and shows all the titles. Some title of Foo remains empty or ”. So, drop down list have lots of empty value because it title is empty. I want to filter out those empty values.

  • 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-23T13:59:30+00:00Added an answer on May 23, 2026 at 1:59 pm

    You can provide your own form for ModelAdmin, with custom queryset for foo field.

    from django import forms
    from django.contrib import admin
    
    #Create custom form with specific queryset:
    class CustomBarModelForm(forms.ModelForm):
        class Meta:
            model = Bar
            fields = '__all__'
    
        def __init__(self, *args, **kwargs):
            super(CustomBarModelForm, self).__init__(*args, **kwargs)
            self.fields['foo'].queryset = Foo.objects.filter(title__isnull=False)# or something else
    
    # Use it in your modelAdmin
    class BarAdmin(admin.ModelAdmin):
        form = CustomBarModelForm
    

    Something like this…

    docs

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

Sidebar

Related Questions

class Foo(models.Model): title = models.CharField(max_length=20) slug = models.SlugField() Is there a built-in way to
I have the following model and instance: class Bashable(models.Model): name = models.CharField(max_length=100) >>> foo
say I have such model: class Foo(models.Model): name = models.CharField(name,max_length=25) type = models.IntegerField(type number)
With Django models, I want to achieve this: class Foo(models.Model): name = models.CharField(max_length=50) #wrapping
Assume I have such simple model: class Foo(models.Model): name = models.CharField(max_length=25) b_date = models.DateField()
Say I have the following models: class Baz(models.Model): winning = models.CharField(max_length=100) class Bar(models.Model): baz
I'm working with a model: class Foo(models.Model): name = models.CharField(max_length=255) bars = models.ManyToManyField('Bar') In
I have (essentially) the following models: class foo(models.model): name = models.CharField(max_length=255) size = models.PositiveIntegerField()
I have this Model in django : class Post(models.Model): title = models.CharField(max_length=255) category =
Assume I have a such model: class Foo(models.Model): name = models.CharField(ad,max_length=25) type = models.ForeignKey(Type)

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.