access couchdb form with couchdbkit in django

527 Views Asked by At

I was able to reproduce successfully the greeting example from couchdbkit form django extension

However, I essentially replicated the same example to work with an existing couchdb data base called projects but come up with the following error:

Exception Value:
None Exception Location: /usr/lib/python2.7/site-packages/couchdbkit/schema/util.py in wrap, line 29 So I wonder what creates that exception

here is my models.py

from django.db import models
# Create your models here.
from couchdbkit.ext.django.schema import *
from couchdbkit.ext.django.forms import *
from datetime import datetime
from couchdbkit import Document
from couchdbkit import *
from couchdbkit.ext.django.forms  import DocumentForm
from couchdbkit.ext.django.forms  import *
class project(Document):
    name = StringProperty()
    type = StringProperty(required=True,default="project")
    created_at = DateTimeProperty(default=datetime.utcnow)

here is my forms.py

from django.db import models
# Create your form here.
from couchdbkit.ext.django.schema import *
from couchdbkit.ext.django.forms import *
from datetime import datetime
from couchdbkit import Document
from couchdbkit import *
from couchdbkit.ext.django.forms  import DocumentForm
from couchdbkit.ext.django.forms  import *
class projectForm(DocumentForm):    
     class Meta:
         document = project

Here is my views.py

# Create your views here.
from django.shortcuts import render_to_response as render
from django.shortcuts import render_to_response
from django.http import HttpResponse
from datetime import datetime
from couchdbkit import Document
from couchdbkit import *
from couchdbkit.ext.django.forms  import DocumentForm
from couchdbkit.ext.django.forms  import *
from django import forms
from django.template import Context, Template
from django.template import RequestContext, loader, Context
from django.http import HttpResponseRedirect
from projects.models import project
from projects.models import Building
from couchdbkit.ext.django.loading import get_db

db = get_db('projects')
class projectForm(DocumentForm):    
    class Meta:
        document = project
class BuildingForm(DocumentForm):    
     class Meta:
         document = Building
def home(request):
    project.set_db(db) 
    greet = None
    if request.POST:
        form = projectForm(request.POST)
        if form.is_valid():
            greet = form.save()
            return render_to_response('dbcontent.html',{'row':db})
    else:
        form = projectForm()
    projects = project.view("projects/all")
    return render("home.html", {
        "form": form,
        "greet": greet,
        "projects": projects,
    }, context_instance=RequestContext(request))

This is my home.html

{% extends "base.html" %}
{% load i18n %} 
{% block content %}
            <form contact="/project/" method="post"> {% csrf_token %}
                <table>
                {{ form.as_table }}
                </table>
                <input type="submit" id="submit" value="submit">
            </form>
            {% if greet %}
            {{ greet.get_id }} was added
            {% endif %}
            <h2>Projects</h2>
            <table>
            {% for p in projects %}
                <tr>
                    <td>{{ p.timestamp|timesince }} </td>
                    <td>{{ p.name }} </td>
                    <td>{{ p.type }}</td>
                </tr>
            {% endfor %}
            </table>
        {% endblock content %}

So Django indexes the following line on my home.html as origin of the exception

{% for p in projects %}

and gives me the error mentioned above.

But notice that in my home.html if I replace {% for p in projects %} with {% for p in home %} the error is gone but just the form shows up, and there is no data retrieval from couchdb

I am pretty confident that the error has to do with this statement in my views projects = project.view("projects/all")

So what am I missing here? Thanks in advance and I apologise if you see some redundancy in my declarations.

0

There are 0 best solutions below