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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:51:11+00:00 2026-06-08T01:51:11+00:00

I’m trying to have a Django Form from a query, but I keep doing

  • 0

I’m trying to have a Django Form from a query, but I keep doing it the wrong way. Checked out a few examples, but I’m doing it a bit different. Here’s my code,

Le Form

class ItemForm(ModelForm):

    class Meta:
        model = Item
        exclude = ('deleted')

And part of the view

def index(request):
    user = User
    try:
        last_modified_list = ShoppingList.objects.filter(deleted='0').filter(owner=user).latest('date_modified')
        items = Item.objects.filter(shopping_list=last_modified_list).filter(deleted='0')
    except ObjectDoesNotExist:
        items = Item.objects.filter(deleted='0')

    last_used_currency = ExtendedUser.objects.filter(owner=user)

    #currency = forms.CharField(initial=last_used_currency.last_currency)
    try:
        last_used_shoppinglist = ShoppingList.objects.filter(deleted='0').filter(owner=user).latest('date_modified')
    except ObjectDoesNotExist:
        last_used_shoppinglist = datetime.datetime.now()

    item_form = ItemForm (request.POST or None)
    item_form.fields["shopping_list"]=last_used_shoppinglist




    if item_form.is_valid():
        name =  item_form.cleaned_data['name']
        bought =  item_form.cleaned_data['bought']
        currency = item_form.cleaned_data['currency']
        price = item_form.cleaned_data['price']
        date_added = item_form.cleaned_data['date_added']
        date_modified = item_form.cleaned_data['date_modified']
        date_bought = item_form.cleaned_data['date_bought']
        shopping_list = item_form.cleaned_data['shopping_list']
        quantity = item_form.cleaned_data['quantity']
        deleted = item_form.cleaned_data['deleted']

    return render_to_response ('base.html',{'user':user,'items':items,'item_form':item_form}, context_instance=RequestContext(request))

The shopping_list line is really leading to many errors.

  • 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-08T01:51:12+00:00Added an answer on June 8, 2026 at 1:51 am

    You want to pass the object into the form as “instance”. If I understand your code correctly and you had a single Item named “item”:

    ItemForm(request.POST or None, instance=item)
    

    In this case though, it looks like you want a model formset so you can edit multiple items at once. Then you would pass your items variable in as the “queryset” parameter.

    EDIT: Actual solution is for a different problem,

    item_form.fields["shopping_list"].initial = last_used_shoppinglist
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
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

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.