can somebody help me out of newform,i spend one whole day to study
djangosnipppets.com's newform, but it did not work for me.

models.py:
class Vendor(models.Model):

        name = models.CharField(maxlength=100)
        slug = models.SlugField()

class Type(models.Model):

        vendor = models.ForeignKey(Vendor)
        name = models.CharField(maxlength=100)
        description = models.TextField()

forms.py:
from django import newforms as forms
from models import Vendor

attrs_dict = { 'class': 'required' }

class AddTypeForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(AddTypeForm, self).__init__(*args, **kwargs)
        self.fields['language'].choices = [('', '----------')] +
[(x.id, x.name) for x in Vendor.objects.all()]


        name = forms.CharField(max_length=100,
widget=forms.TextInput(attrs=attrs_dict))
        description =
forms.CharField(widget=forms.Textarea(attrs=attrs_dict))
        vendor = forms.ChoiceField(choices=(),
widget=forms.Select(attrs=attrs_dict))

views.py:
def add_car(request):

    if request.method == 'POST':
        form = forms.AddTypeForm(request.POST)
        if form.is_valid():
            new_type = Type(name=form.clean_data['name'],
 
description=form.clean_data['description'],
 
vendor_id=form.clean_data['vendor'],
                   )
            new_type.save()
            return HttpResponseRedirect(new_type.get_absolute_url())
    else:
        form = forms.AddTypeForm()
    return render_to_response('rate/add_car_form.html',
                              { 'form': form },
 
context_instance=RequestContext(request))
add_car = login_required(add_car)

templates:
........


and i got this error:

Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1/cars/add/

No Vendor matches the given query.



can somebody help me, thanks!!!!!


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to