Snippet must be a class, see i'm not sure because i am following an example from a book online and some of the pages aren't displayed, so i don't no what is in snippet.
how do i use a ModelForm, i only know how to use a model and form separatly? On Apr 16, 3:15 pm, Daniel Roseman <dan...@roseman.org.uk> wrote: > On Apr 16, 3:08 pm, JoJo <culligan.joanne...@gmail.com> wrote: > > > > > > > Hi all, i am new to django, i was following an example online of how > > to use forms, the one i am on at the min is a user page, where the > > form accepts the submitted data, i have the html page displaying but > > when i click submit i get this error > > > Environment: > > > Request Method: POST > > Request URL:http://localhost:8000/add_gossip/ > > Django Version: 1.1.1 > > Python Version: 2.6.4 > > Installed Applications: > > ['django.contrib.admin', > > 'django.contrib.auth', > > 'django.contrib.contenttypes', > > 'django.contrib.sessions', > > 'django.contrib.sites', > > 'gossip2go.applications'] > > Installed Middleware: > > ('django.middleware.common.CommonMiddleware', > > 'django.contrib.sessions.middleware.SessionMiddleware', > > 'django.contrib.auth.middleware.AuthenticationMiddleware') > > > Traceback: > > File "c:\Python26\lib\site-packages\django\core\handlers\base.py" in > > get_response > > 92. response = callback(request, *callback_args, > > **callback_kwargs) > > File "c:\django\gossip2go\..\gossip2go\applications\views.py" in > > add_gossip > > 188. new_gossip = form.save() > > File "c:\django\gossip2go\applications\models.py" in save > > 138. return Snippet.objects.create(title > > =self.cleaned_data['title'], > > > Exception Type: NameError at /add_gossip/ > > Exception Value: global name 'Snippet' is not defined > > > Here is my views.py file > > > def add_gossip(request): > > if request.method == 'POST': > > form = AddStuffForm(author=request.user, data=request.POST) > > if form.is_valid(): > > new_gossip = form.save() > > return HttpResponseRedirect("/links/") > > else: > > form = AddStuffForm(author=request.user) > > return render_to_response('add_gossip.html', > > { 'form': form}) > > > Here is my model.py file > > > class AddStuffForm(forms.Form): > > def __init__(self,author, *args, **kwarfs): > > super(AddStuffForm, self).__init__(*args, **kwarfs) > > self.author = author #could be problem here with indentation > > and __ > > > title = forms.CharField(max_length=100) > > description = forms.CharField(widget = forms.Textarea()) > > code = forms.CharField(widget = forms.Textarea()) > > tags = forms.CharField(max_length=200) > > > def save(self): > > return Snippet.objects.create(title > > =self.cleaned_data['title'], > > description = > > self.cleaned_data['description'], > > code = > > self.cleaned_data['code'], > > tags = > > self.cleaned_data['tags'], > > author = > > self.author) > > > i have tried to change around the return line but i just keep getting > > errors > > if anyone can help me with this it would be great, thanks in advance > > What is Snippet? You can't use it if you haven't imported it. > > Incidentally, if you use a ModelForm the save method will be defined > for you. > -- > DR. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group > athttp://groups.google.com/group/django-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.