Nevermind, I was missing something terribly basic and just needed to stop looking at it for a bit to realize how to combine it.
On May 22, 5:08 pm, Jonathan <kellenb...@gmail.com> wrote: > I am sure this is some very easy and simple concept I am just not > grasping. I have two views which are very similar. Both take the > same variable and iterate the applicable data. I am trying to get > them to render on the same template. However, when I create one as a > template tag and try to pass the common variable, I get variable is > not defined errors. > > def projectfilesindex(request, object_id): > def store() > ... > files = ProjectFileUrl.objects.filter > (project_number=object_id).order_by('-uploaded') > if not request.method == "POST": > form = UploadForm() > return render_to_response( > 'projects/files.html', > {"form": form, "files": files}, > context_instance = RequestContext(request, object_id) > ) > > form = UploadForm(request.POST, request.FILES) > if not form.is_valid(): > return render_to_response( > 'projects/files.html', > {"form": form, "files": files}, > context_instance = RequestContext(request, object_id) > ) > > file = request.FILES["file"] > filename = file.name > content = file.read() > store(...) > p = Project.objects.get(pk=object_id) > f = ProjectFileUrl(url="http://someurl.com/" + object_id + "_" + > filename, > name=object_id + "_" + filename, project_number=p) > f.save() > files = ProjectFileUrl.objects.filter > (project_number=object_id).order_by('-uploaded') > return render_to_response( > 'projects/files.html', > {"form": form, "files": files}, > context_instance = RequestContext(request, object_id) > ) > > def announce(request, object_id): > announcements = ProjectAnnouncement.objects.filter > (project=object_id).order_by('-date_posted') > if not request.method == "POST": > form = ProjectAnnouncementForm() > return render_to_response( > 'projects/announcement.html', > {"form": form, "announcements": announcements}, > context_instance = RequestContext(request) > ) > form = ProjectAnnouncementForm(request.POST) > if not form.is_valid(): > return render_to_response( > 'projects/files.html', > {"form": form, "announcements": announcements}, > context_instance = RequestContext(request) > ) > title = request.POST['title'] > body = request.POST['body'] > d = datetime.now() > p = Project.objects.get(pk=object_id) > a = ProjectAnnouncement(author_user=request.user, date_posted=d, > project=p, title=title, body=body) > a.save() > announcements = ProjectAnnouncement.objects.filter > (project=object_id).order_by('-date_posted') > return render_to_response( > 'projects/announcement.html', > {"form": form, "announcements": announcements}, > context_instance = RequestContext(request) > ) > > As they both stand, they work separately. Every time I try and > combine them, or make one a template tag, I end up with an error, or > only getting one to work and the other fails silently. When I try and > make one into a template tag, I end up with the "object_id" is not > globally defined error. > > I'm sure I am missing something really basic. Does anyone have a > pointer to get me going in the right direction? > > Jonathan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---