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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:10:40+00:00 2026-05-28T18:10:40+00:00

I am a bit puzzled with the Django object models. I have models like

  • 0

I am a bit puzzled with the Django object models. I have models like this:

# Create your models here.
class Item(models.Model):
    code = models.CharField(max_length=200, unique=True)
    barcode = models.CharField(max_length=300)
    desc = models.CharField('Description',max_length=500)
    reg_date = models.DateField('registered date')
    registrar = models.CharField(max_length=100)

    def __unicode__(self):
       return self.code + ' : ' + self.desc

class ItemInfo(models.Model):
    item = models.OneToOneField(Item, primary_key=True)
    supplier = models.ForeignKey(Supplier)
    stock_on_hand = models.IntegerField()
    stock_on_order = models.IntegerField()
    cost = models.IntegerField()
    price = models.IntegerField()
    unit = models.CharField(max_length=100)
    lead_time = models.IntegerField() 

But when I tried to retrieve the Item and ItemInfo into modelforms, I got this error:
'ModelFormOptions' object has no attribute 'many_to_many'. I suspected there is something wrong with this line supplier = models.ForeignKey(Supplier). Can someone explained me when to use ForeignKeyor the relationships fields (OneToOneFields, ManyToManyFields, ManyToOneFields)

Edit: ModelForm:

class ItemForm(ModelForm):
    class Meta:
        model = Item
        widgets = {
            'registrar' : TextInput(attrs={'ReadOnly' : 'True'})
        }

class ItemInfoForm(ModelForm):
    class Meta:
        model = ItemInfo
        exclude = ('item')

This is how I generate the form with populated value from the models:

def details(request, code):
    csrf_context = RequestContext(request)
    current_user = User
    if request.user.is_authenticated():
         item = Item.objects.get(pk=code)
         item_info = ItemInfo.objects.get(pk=item.pk)
         item_form = ItemForm(instance=item)
         item_info_form = ItemInfoForm(instance=item_form)
         return render_to_response('item/details.html',
                                   {'item_form' : item_form, 'item_info_form' :      item_info_form},
                                   csrf_context)
    else:
        return render_to_response('error/requires_login.html', csrf_context)

Traceback:
 Traceback:
 File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "G:\tulip\stock\item\views.py" in details
   131.         item_info_form = ItemInfoForm(instance=item_form)
File "C:\Python27\lib\site-packages\django\forms\models.py" in __init__
   237.             object_data = model_to_dict(instance, opts.fields, opts.exclude)
File "C:\Python27\lib\site-packages\django\forms\models.py" in model_to_dict
   112.     for f in opts.fields + opts.many_to_many:

Exception Type: AttributeError at /item/details/1/
Exception Value: 'ModelFormOptions' object has no attribute 'many_to_many'
  • 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-28T18:10:41+00:00Added an answer on May 28, 2026 at 6:10 pm

    You are instantiating ItemInfoForm with ItemForm instance. While instance should be ItemInfo instance, not form

    Correct line:

    item_info_form = ItemInfoForm(instance=item_info)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a bit puzzled to something we got here at the office. We have
I am a bit puzzled by this strange behavior on CentOs 5.4 when starting
I'm going through a Fortran code, and one bit has me a little puzzled.
I'm no javascript wiz, but am a bit puzzled as to how this is
I am a bit puzzled by the sensor reading rates in Android. The code
I found some confusing code during code review and am a bit puzzled. Doing
I'm a bit puzzled by this one. There are some methods in the Java
While trying to optimize a code, I'm a bit puzzled by differences in profiles
Good day, I'm puzzled a bit with this: In[1]:= f[x_]:=With[{xx=x},f[xx_]:=ff[xx]] DownValues[f] f[1] DownValues[f] Out[2]=
I am a bit puzzled on the following.. A domain model consists of a

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.