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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:18:28+00:00 2026-06-14T17:18:28+00:00

I’m trying to load a distinct list of values into a ModelChoiceField . class

  • 0

I’m trying to load a distinct list of values into a ModelChoiceField.

class myform(ModelForm):
    content = forms.FileField()
    def distinct_mans():
        manufacturers = UniPart.objects.all().values('manufacturer').distinct()
        return manufacturers
    manufacturer = forms.ModelChoiceField(queryset=distinct_mans)

To clarify, manufacturer is a field in the UniPart table. I want to get all distinct manufacturers and put that in the drop-down menu.

However I’m getting this error:

'function' object has no attribute 'all'

Traceback:

Template error:
In template /Users/nb/Desktop/modelstore/mymodels/templates/mymodels/add_model.html, error at line 24
   'function' object has no attribute 'all'
   14 :             {% csrf_token %}


   15 :             <br>


   16 :             <div style="float: left; width: 200px">


   17 :             <h6>Model Name</h6>


   18 :             <br>


   19 :             {{ formtoaddmodel.modelname }}


   20 :             <br>


   21 :             <br>


   22 :             <h6>Manufacturer</h6>


   23 :             <br>


   24 :              {{ formtoaddmodel.manufacturer }} 



Traceback:

    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
      111.                         response = callback(request, *callback_args, **callback_kwargs)
    File "/Users/nb/Desktop/modelstore/mymodels/views.py" in add_model
      652.          }, context_instance=RequestContext(request,{}))
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/shortcuts/__init__.py" in render_to_response
      20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
      176.         return t.render(context_instance)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in render
      140.             return self._render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/test/utils.py" in instrumented_test_render
      62.     return self.nodelist.render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in render
      823.                 bit = self.render_node(node, context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/debug.py" in render_node
      74.             return node.render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/loader_tags.py" in render
      123.         return compiled_parent._render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/test/utils.py" in instrumented_test_render
      62.     return self.nodelist.render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in render
      823.                 bit = self.render_node(node, context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/debug.py" in render_node
      74.             return node.render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/loader_tags.py" in render
      123.         return compiled_parent._render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/test/utils.py" in instrumented_test_render
      62.     return self.nodelist.render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in render
      823.                 bit = self.render_node(node, context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/debug.py" in render_node
      74.             return node.render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/loader_tags.py" in render
      123.         return compiled_parent._render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/test/utils.py" in instrumented_test_render
      62.     return self.nodelist.render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in render
      823.                 bit = self.render_node(node, context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/debug.py" in render_node
      74.             return node.render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/loader_tags.py" in render
      62.             result = block.nodelist.render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in render
      823.                 bit = self.render_node(node, context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/debug.py" in render_node
      74.             return node.render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/loader_tags.py" in render
      62.             result = block.nodelist.render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/base.py" in render
      823.                 bit = self.render_node(node, context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/debug.py" in render_node
      74.             return node.render(context)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/template/debug.py" in render
      87.             output = force_unicode(output)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/utils/encoding.py" in force_unicode
      71.                 s = unicode(s)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/forms/forms.py" in __unicode__
      411.         return self.as_widget()
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/forms/forms.py" in as_widget
      458.         return widget.render(name, self.value(), attrs=attrs)
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/forms/widgets.py" in render
      547.         options = self.render_options(choices, [value])
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/forms/widgets.py" in render_options
      570.         for option_value, option_label in chain(self.choices, choices):
    File "/Users/nb/Desktop/myenv2/lib/python2.7/site-packages/django/forms/models.py" in __iter__
      896.             for obj in self.queryset.all():

    Exception Type: AttributeError at /mymodels/add
    Exception Value: 'function' object has no attribute 'all'
  • 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-14T17:18:29+00:00Added an answer on June 14, 2026 at 5:18 pm

    Well, the queryset argument is expecting a queryset, not a function.

    But the function is unnecessary – you can do this:

    manufacturer = forms.ModelChoiceField(queryset=UniPart.objects.all().values('manufacturer').distinct())
    

    which should do exactly what you want.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.