Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#14899 closed (invalid)

'ModelFormOptions' object has no attribute 'many_to_many'

Reported by: silent1mezzo Owned by: nobody
Component: Forms Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


When trying to use the modelformset_factory I get the following error.

Request Method: GET
Django Version: 1.2.3
Python Version: 2.6.6

File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/core/handlers/" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/views/decorators/" in _wrapped_view_func
  69.         response = view_func(request, *args, **kwargs)
File "/home/webdev/web/virtualenvs/polaris/polaris/apps/smart_project/" in update
  46.     ServiceFormSet = modelformset_factory(ServiceForm)
File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/forms/" in modelformset_factory
  675.                              formfield_callback=formfield_callback)
File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/forms/" in modelform_factory
  413.     return ModelFormMetaclass(class_name, (form,), form_class_attrs)
File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/forms/" in __new__
  226.                                       opts.exclude, opts.widgets, formfield_callback)
File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/forms/" in fields_for_model
  167.     for f in opts.fields + opts.many_to_many:

Exception Type: AttributeError at /smart/update/awefawf/
Exception Value: 'ModelFormOptions' object has no attribute 'many_to_many'

Here's my model

class Services(models.Model):
    departure_id = models.ForeignKey(Departures)
    service_name = models.TextField()
    service_code = models.CharField(max_length=20)
    service_date = models.DateField()
    service_type = models.CharField(max_length=40)
    paid_by = models.CharField(max_length=40)
    cost = models.DecimalField(max_digits=10, decimal_places=2)
    cost_currency = models.CharField(max_length=6)
    deleted = models.BooleanField()
    deleted_by = models.IntegerField()
    deleted_reason = models.TextField()
    validated = models.BooleanField()
    validated_by = models.IntegerField()
    updated = models.DateField(auto_now=True)

Here's my form

class ServiceForm(forms.ModelForm):
    class Meta:
        model = Services
        exclude = ('departure_id',)

Here's my initialization

ServiceFormSet = modelformset_factory(ServiceForm)

Change History (2)

comment:1 Changed 6 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

You're passing the Form as the model parameter.

signature is: def modelform_factory(model, form=ModelForm, fields=None, exclude=None, formfield_callback=None):

comment:2 Changed 6 years ago by anonymous

ehh wrong copy paste:

def modelformset_factory(model, form=ModelForm, formfield_callback=None,

extra=1, can_delete=False, can_order=False,
max_num=None, fields=None, exclude=None):

Note: See TracTickets for help on using tickets.
Back to Top