Hi Djangoers, I have an issue I can't work out. This is the situation:
I have a model called payment, which has a custom constructor which takes a parameter. This is the code: class Payment(models.Model): id = models.AutoField(primary_key=True) amount = models.FloatField("Total payment amount") ... def __init__(self, business, *args, **kwargs): super(Payment, self).__init__(*args, **kwargs) self.business = business Then in my forms file I have this model form: class PaymentForm(forms.ModelForm): class Meta: model = Payment def __init__(self, *args, **kwargs): self.business = kwargs.pop('business') super(PaymentForm, self).__init__(*args, **kwargs) The problem I have is that when I try to create an instance of this form with: form = PaymentForm(request.GET, business=business) I get the following error: TypeError at /payment/ __init__() takes at least 2 arguments (1 given) The stacktrace shows that it fails on self.instance = opts.model() ... in this location. /django/forms/models.py in __init__ initial=None, error_class=ErrorList, label_suffix=':', empty_permitted=False, instance=None): opts = self._meta if instance is None: if opts.model is None: raise ValueError('ModelForm has no model class specified.') # if we didn't get an instance, instantiate a new one self.instance = opts.model() ... object_data = {} else: self.instance = instance object_data = model_to_dict(instance, opts.fields, opts.exclude) # if initial was provided, it should override the values from instance if initial is not None: I think I need to somehow pass the business object to model = Payment inside the Meta class... Is this the case and does anyone know how to do it? I have remove the constructor from the model and everything works. Thanks a million! -m -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.