at first: please excuse my bad english. I hope you can understand what
i mean.
i just started working with Django and used the tutorial @
djangoproject.com.
After i completed it i tried to rebuild the djangotutorial for
wikicamp shown on ShowMeDo ( http://showmedo.com/videotutorials/video?name=1100000&fromSeriesID=110
). I recognized that it's an old version of django he used, so i
successfully solved all issues until I tried to rebuild the first half
of the third video. Its about manytomany relations.
Now I got the problem, when i send the form with the Pagedata and one
or More Tags (there is the ManyToMany relation, On or More pages can
have one or more Tags) it tells me that the needed model doesn't
exists. And it calls the model wiki_page_tags , but i got a model Page
and a model Tags.
The error message shows following code phrase:
for tag in tag_list:
page.tags.add(tag)
As attachment there are the Views.py and the Models.py. If You need
more Information to solve my problem, please let me know.
I use a SQLite DB and thats my views.py:
from djangotutorial.wiki.models import Page, Tag
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.template import RequestContext
from django import forms
class SearchForm(forms.Form):
text = forms.CharField(label="Enter search term")
search_content = forms.BooleanField(label="Search content",
required=False)
def search_page(request):
if request.method == "POST":
f = SearchForm(request.POST)
if not f.is_valid():
return render_to_response("wiki/search.html", {"form":f},
context_instance=RequestContext(request))
else:
pages = Page.objects.filter(name__contains =
f.cleaned_data["text"])
contents = []
if f.cleaned_data["search_content"]:
contents = Page.objects.filter(content__contains =
f.cleaned_data["text"])
return render_to_response("wiki/search.html", {"form":f,
"pages":pages, "contents":contents},
context_instance=RequestContext(request))
f = SearchForm()
return render_to_response("wiki/search.html", {"form":f},
context_instance=RequestContext(request))
specialPages = {"SearchPage": search_page}
def view_page(request, page_name):
if page_name in specialPages:
return specialPagespage name(request)
try:
page = Page.objects.get(pk=page_name)
except Page.DoesNotExist:
return render_to_response('wiki/create.html',
{'page_name':page_name})
content = page.content
return render_to_response("wiki/view.html",
{"page_name":page_name, "content":content})
def edit_page(request, page_name):
try:
page = Page.objects.get(pk=page_name)
content = page.content
except Page.DoesNotExist:
content = ""
return render_to_response("wiki/edit.html",
{"page_name":page_name, "content":content},
context_instance=RequestContext(request))
def save_page(request, page_name):
content = request.POST["content"]
tag_list = []
if "tags" in request.POST:
tags = request.POST["tags"]
tag_list = [Tag.objects.get_or_create(name=tag) for tag in
tags.split()]
try:
page = Page.objects.get(pk=page_name)
page.content = content
for tag in tag_list:
page.tags.add(tag)
except Page.DoesNotExist:
page = Page(name=page_name, content=content)
page.save()
return HttpResponseRedirect("/wiki/page/" + page_name + "/")
and the models.py:
from django.db import models
# Create your models here.
class Tag(models.Model):
name = models.CharField(max_length=20, primary_key=True)
class Page(models.Model):
name = models.CharField(max_length=20, primary_key=True)
content = models.TextField(blank=True)
tags = models.ManyToManyField(Tag)
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment