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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:20:09+00:00 2026-06-02T05:20:09+00:00

So I have this custom ModelForm that I created that takes in a variable

  • 0

So I have this custom ModelForm that I created that takes in a variable creator_list for the queryset like this:

class UserModelChoiceField(ModelChoiceField):
    def label_from_instance(self, obj):
        return obj.get_full_name()

class OrderCreateForm(ModelForm):
    class Meta:
        model=Order
        fields=('work_type', 'comment',)

    def __init__(self, creator_list=None, *args, **kwargs):
        super(OrderCreateForm, self).__init__(*args, **kwargs)

        if creator_list:
            self.fields['creator'] = UserModelChoiceField(
                queryset=creator_list,
                empty_label="Select a user",
                widget=Select(attrs={
                    'onchange': "Dajaxice.doors.orders_create_creator_changed(fill_other_fields, {'creator_pk': this.options[this.selectedIndex].value})"
                })
            )

        self.fields['place'] = UserModelChoiceField(
            queryset=User.objects.none(),
            empty_label="Select a creator first"
        )

When I am simply displaying the fields, everything works perfectly. However during a POST submission. I get errors that I don’t know how to debug.

My views.py looks like this:

user = request.user
dictionary = get_order_create_dictionary(user)

if request.method == 'POST':
    #import ipdb; ipdb.set_trace()

    form = OrderCreateForm(request.POST)

    if form.is_valid():
        creator   = form.cleaned_data['creator']
        place     = form.cleaned_data['place']
        work_type = form.cleaned_data['work_type']
        comment   = form.cleaned_data['comment']

        new_order = Order.objects.create(
            creator  =creator,
            place    =place,
            work_type=work_type,
            comment  =comment
        )

        messages.success(request, "Your order #{} had been created!".format(new_order.pk))
        logger.info("{user} created order #{pk}".format(user=user, pk=new_order.pk))

        return HttpResponseRedirect(reverse('orders_detail', kwargs={'pk': new_order.pk}))
    else:
        return render(request, 'doors/orders/create.html', {'form': form, 'can_assign_creator': dictionary['can_assign_creator']})
else:
    if dictionary:
        return render(request, 'doors/orders/create.html', {
            'form': OrderCreateForm(creator_list=dictionary['creator_list']),
            'can_assign_creator': dictionary['can_assign_creator']
        })
    else:
        return HttpResponseRedirect(reverse('orders_list'))

get_order_create_dictionary() simply returns a dictionary that looks like this:

dictionary = {
    'creator_list': Order.objects.all(), # Or some kind of filtered Order.
    'can_assign_order: 1, # Or 0. This variable is used in the template to control access to what gets displayed.
} 

Currently with the above code I get an error like this when I try to POST something:

AttributeError: 'QueryDict' object has no attribute 'all'
on the line "return render(request, 'doors/orders/create.html', {'form': form, 'can_assign_creator': dictionary['can_assign_creator']})"

I thought it has something to do with the line form = OrderCreateForm(request.POST) so I changed that to form = OrderCreateForm(request.POST, creator_list=dictionary['creator_list']). But then I get this error:

TypeError: __init__() got multiple values for keyword argument 'creator_list'
on the line "form = OrderCreateForm(request.POST, creator_list=dictionary['creator_list'])"

I have no clue how to resolve this. I appreciate any help or tips! Thanks!

EDIT:

I changed the line to form = OrderCreateForm(dictionary['creator_list'], request.POST) and now the validation works, but it won’t let me submit a valid POST. It keeps saying Select a valid choice. That choice is not one of the available choices. for the place. This probably has something to do with how I populate the <option> with place using Ajax depending on what the creator is.

  • 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-02T05:20:11+00:00Added an answer on June 2, 2026 at 5:20 am

    You’d better instantiate Form instances with only named arguments, i.e.

    form = OrderCreateForm(creator_list=dictionary['creator_list'], data=request.POST)
    

    One exception is when form only has one argument – the data. This will help you to avoid messing up with arguments order (which is the reason of your errors here).

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

Sidebar

Related Questions

I have a custom class that uses boost mutexes and locks like this (only
I have this: class OrderForm(ModelForm): class Meta: model = Order exclude = ('number',) def
I have this custom textbox that I am working on and I can use
So I have this page that has some basic custom tabs: http://demo.unlockedmanagement.com/users/view/2 * NOTE
I have a custom jsp tag like this: <a:customtag> The body of the custom
I have this custom class which extends EventDispatcher private var assetsManager:AssetManager; And this running
I have this custom wpf user control: ShowCustomer.xaml: <UserControl x:Class=TestControlUpdate2343.Controls.ShowCustomer xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml> <Grid> <TextBlock
I have a model like this: class Item(models.Model): code = models.CharField(max_length=200, unique=True) barcode =
I have this custom primary key in a model: class Personal(models.Model): name = models.CharField(max_length=20,primary_key=True)
I have this custom error handler: `class AppError extends ErrorHandler { function error404($params) {

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.