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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:49:16+00:00 2026-05-30T21:49:16+00:00

I am using django-selectable and having trouble saving the id (‘autocomplete_1’) which represents the

  • 0

I am using django-selectable and having trouble saving the “id” (‘autocomplete_1’) which represents the id for the category — from the template.

models.py

class Category(models.Model):
cat_no = models.IntegerField(null=True, blank=True)
cat_txt = models.CharField(max_length=45)    
def __unicode__(self):
    return self.cat_txt

class Cattest(models.Model):
category = models.ForeignKey(Category)    
info = models.CharField(max_length=35, blank=True) 

lookups.py

class CategoryLookup(ModelLookup):
model = Category
search_fields = ('cat_txt__icontains', )

forms.py

class CategoryForm(forms.Form):
autocomplete = forms.CharField(
    label='Type the name of a category (AutoCompleteWidget)',
    widget=selectable.AutoCompleteWidget(CategoryLookup),
    required=False,
)
autocompleteselect = selectable.AutoCompleteSelectField(
    lookup_class=CategoryLookup,
    label='Select a category (AutoCompleteField)',
    required=False,
)

class CattestForm(forms.Form):
#model = cattest
#fields = ('category', 'info')
autocomplete = forms.CharField(
    label='Type the name of a category (AutoCompleteSelectWidget)',
    widget=selectable.AutoCompleteSelectWidget(CategoryLookup),
    required=False,
)
info = forms.CharField(max_length=35, label="Information")   

views.py

def cattest(request):
if request.method == 'POST':
    form = CattestForm(request.POST)
    if form.is_valid():
        cattest = Cattest.objects.create(
            category=form.cleaned_data['autocomplete_1'],
            info=form.cleaned_data['info'],
        )
        # Always redirect after a POST
        return http.HttpResponseRedirect('/bsmain/login_customer')            
else:
    if request.GET:
        form = CattestForm(initial=request.GET)
    else:
        form = CattestForm()
return render_to_response('bsmain/form.html', {'form': form}, context_instance=RequestContext(request))

Traceback:

KeyError at /bsmain/cattest/

‘autocomplete_1’

Request Method: POST
Request URL: http://127.0.0.1:8000/bsmain/cattest/
Django Version: 1.3.1
Exception Type: KeyError
Exception Value:

‘autocomplete_1’

Exception Location: /home/bill/workspace/boatsite/../boatsite/bsmain/views.py in cattest, line 64
Python Executable: /usr/bin/python
Python Version: 2.6.5

Request information

GET No GET data
POST Variable Value

   info             u'44# Bruce'
   csrfmiddlewaretoken     u'9ffe49bd68be04087521e71e86a5bec0'
   autocomplete_1   u'10'
   autocomplete_0   u'Anchors'
  • 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-30T21:49:17+00:00Added an answer on May 30, 2026 at 9:49 pm

    The form cleaned_data dictionary is populated based on the field names. You should access the data from form.cleaned_data['autocomplete'].

    Edit:

    This would probably be easier by using a ModelForm:

    class CattestForm(forms.ModelForm):
    
        class Meta:
            model = Cattest
            fields = ('category', 'info', )
            widgets = {
                'category': selectable.AutoCompleteSelectWidget(CategoryLookup)
            }
    
    
    def cattest(request):
        if request.method == 'POST':
            form = CattestForm(request.POST)
            if form.is_valid():
                cattest = form.save()
                # Always redirect after a POST
                return http.HttpResponseRedirect('/bsmain/login_customer')            
        else:
            initial = request.GET or None
            form = CattestForm(initial=initial)
        return render_to_response('bsmain/form.html', {'form': form}, context_instance=RequestContext(request))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using django 1.3 I'm using a base.html template which my pages inherit from.
Using Django's built in models, how would one create a triple-join between three models.
Using Django 1.1, I am trying to select the maximum value from a varchar
I am having problems using django-tagging . I try to follow the documentation but
I am currently using Django to construct JSON encoded objects which a retrieved using
Using Django 1.1.1 In models.py: class Site(models.Model): name = models.CharField(max_length=50) class SiteMonth(models.Model): site =
When using django with apache which is the best server config? Should I use
(Using django as an example; the ForeignKey is implicit in the example) >>> from
Im using Django 1.3.1.In my django code, i have the following template for the
I'm using django.core.mail.EmailMultiAlternatives when sending e-mails from my django app in an attempt to

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.