user1778743 user1778743 - 1 year ago 93
Python Question

overriding modelform choices with __init__

I've been trying to get the fields for a choice to change based on what i give it in my view and i get

name 'self' is not defined

here is my

def CarOwnerSearch(request):
if request.user.is_authenticated():
form = carOwnerForm.__init__(self,'B','None','C')
return render (request,'carmanager/CarOwnerSearch.html', {'form': form})

OK ive got a modelform

class carOwnerForm(forms.ModelForm):
first_name = forms.charfield()
last_name = forms.charfield()

def __init__(self, a,b,c):
self.field["ownership_Type"].choice = [a,b,c]

class Meta:
model = CarOwner
fields = ['ownership_type','CarModel']

and this is my

class CarOwner(models.Model):
ownershipTpes_choices = ( ('R','Rented'),('L','Leased'),('O','Owned'))
ownership_Type = models.CharField(max_length=1,

Answer Source

This is how you would be initializing the form:

form = carOwnerForm.__init__(self,'B','None','C')

should be

form = carOwnerForm('B', None, 'C')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download