Code

Opened 3 years ago

Closed 3 years ago

Last modified 3 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:

Description

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

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

Traceback:
File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/core/handlers/base.py" 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/cache.py" in _wrapped_view_func
  69.         response = view_func(request, *args, **kwargs)
File "/home/webdev/web/virtualenvs/polaris/polaris/apps/smart_project/views.py" in update
  46.     ServiceFormSet = modelformset_factory(ServiceForm)
File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/forms/models.py" in modelformset_factory
  675.                              formfield_callback=formfield_callback)
File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/forms/models.py" 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/models.py" in __new__
  226.                                       opts.exclude, opts.widgets, formfield_callback)
File "/home/webdev/web/virtualenvs/polaris/lib/python2.6/site-packages/django/forms/models.py" 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)

Attachments (0)

Change History (2)

comment:1 Changed 3 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 3 years ago by anonymous

ehh wrong copy paste:

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

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.