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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:29:50+00:00 2026-05-15T13:29:50+00:00

Here is my model class RecipeIngredient(models.Model): recipe = models.ForeignKey(Recipe) ingredient = models.ForeignKey(Ingredient) serving_size =

  • 0

Here is my model

class RecipeIngredient(models.Model):
    recipe = models.ForeignKey(Recipe)
    ingredient = models.ForeignKey(Ingredient)
    serving_size = models.ForeignKey(ServingSize)
    quantity = models.IntegerField()
    order = models.IntegerField()
    created = models.DateTimeField(auto_now_add = True)
    updated = models.DateTimeField(auto_now = True)

and my model form

class RecipeIngredientForm(forms.ModelForm):
    recipe_ingredient = forms.CharField()

    class Meta:
        model = RecipeIngredient

        widgets = {
            'serving_size' : forms.Select(attrs={'class' : 'test'}), 
            'recipe_ingredient' : forms.TextInput(),
        }

I get the following error when I navigate to the page

Unhandled exception in thread started by <function inner_run at 0x1010faf50>
Traceback (most recent call last):
  File "/Library/Python/2.6/site-packages/django/core/management/commands/runserver.py", line 48, in inner_run
    self.validate(display_num_errors=True)
  File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 245, in validate
    num_errors = get_validation_errors(s, app)
  File "/Library/Python/2.6/site-packages/django/core/management/validation.py", line 28, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/Library/Python/2.6/site-packages/django/db/models/loading.py", line 146, in get_app_errors
    self._populate()
  File "/Library/Python/2.6/site-packages/django/db/models/loading.py", line 61, in _populate
    self.load_app(app_name, True)
  File "/Library/Python/2.6/site-packages/django/db/models/loading.py", line 78, in load_app
    models = import_module('.models', app_name)
  File "/Library/Python/2.6/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/models.py", line 128, in <module>
    RecipeIngredientFormSet = inlineformset_factory(Recipe, RecipeIngredient, extra=1, form=RecipeIngredientForm)
  File "/Library/Python/2.6/site-packages/django/forms/models.py", line 838, in inlineformset_factory
    FormSet = modelformset_factory(model, **kwargs)
  File "/Library/Python/2.6/site-packages/django/forms/models.py", line 669, in modelformset_factory
    formfield_callback=formfield_callback)
  File "/Library/Python/2.6/site-packages/django/forms/models.py", line 407, in modelform_factory
    return ModelFormMetaclass(class_name, (form,), form_class_attrs)
  File "/Library/Python/2.6/site-packages/django/forms/models.py", line 220, in __new__
    opts.exclude, opts.widgets, formfield_callback)
  File "/Library/Python/2.6/site-packages/django/forms/models.py", line 178, in fields_for_model
    formfield = formfield_callback(f, **kwargs)
TypeError: <lambda>() got an unexpected keyword argument 'widget'

but if I remove this line from my RecipeIngredientForm the error goes away

'serving_size' : forms.Select(attrs={'class' : 'test'}), 

Any ideas whatI did wrong?

  • 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-15T13:29:51+00:00Added an answer on May 15, 2026 at 1:29 pm

    Just don’t add Select widget to this field, it’s ModelChoiceField, and is rendered as select box anyway. If you put Select widget on ModelChoiceField, it won’t render properly (will show unicode output in value rather than ID).

    Also you don’t need the first CharField unless you want a text input with auto-completion.

    To show the input element with custom attributes, use {% field %} tag:

    {% field myform.myselect class="XYZ" %}
    

    renders it to

    <select name="..." class="XYZ">...
    

    I think you’ll agree that it’s a bad idea to customize classes and templates inside forms or models. It makes it impossible to debug templates.

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

Sidebar

Related Questions

I have a model with a custom property class RecipeIngredient(models.Model): recipe = models.ForeignKey(Recipe) ingredient
here is my model class gameUserTrophyInfo(models.Model): user = models.ForeignKey(userInfo) trophy = models.ForeignKey(gameTrophyInfo) date =
Here's a snippet from my application: class PortolioItem(models.Model): ... user = models.ForeignKey(User) contract =
Here's my Model: class User(models.Model): pass class Item(models.Model): pass class ItemVote(models.Model): user = models.ForeignKey(User)
Another question on some forms Here is my model class TankJournal(models.Model): user = models.ForeignKey(User)
here is my model : class Page(models.Model): template = models.CharField(max_length=200,blank=True) self_url = models.ForeignKey('liens.Lien',null=True,blank=True) Categorie
Here's my code: class Publisher(models.Model): name = models.CharField( max_length = 200, unique = True,
Here is a Django model I'm using. class Person(models.Model): surname = models.CharField(max_length=255, null=True, blank=True)
Here's part of my Django app's models.py : class Person(models.Model): birth_year = WideYear(null=True, blank=True)
Here is a simplified version of one of my models: class ImportRule(models.Model): feed =

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.