1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 Extension to use couchdbkit in Django 1.x. It allows you to use couchdbkit
19 easily in your django projects.
20
21 Just add to your settings the `COUCHDB_DATABASES` that defines
22
23 COUCHDB_DATABASES = (
24 ('djangoapp.greeting', 'http://127.0.0.1:5984/greeting'),
25 )
26
27 This one define the db greeting on url `http://127.0.0.1:5984/greeting`
28 for the application `greeting`of djangoapp project.
29
30
31 Then add extension to your INSTALLED_APPS before all applications using
32 couchdbkit documents :
33
34 INSTALLED_APPS = (
35 ....
36 'couchdbkit.ext.django',
37 ....
38 )
39
40 Add your documents objects in models.py :
41
42 from couchdbkit.ext.django.schema import *
43 class Greeting(Document):
44 author = StringProperty()
45 content = StringProperty(required=True)
46 date = DateTimeProperty(default=datetimee.utcnow)
47
48 and use it in your views.py :
49
50 class GreetingForm(DocumentForm):
51
52 class Meta:
53 document = Greeting
54
55 def home(request):
56
57 greet = None
58
59 if request.POST:
60 form = GreetingForm(request.POST)
61 if form.is_valid():
62 greet = form.save()
63 else:
64 form = GreetingForm()
65
66 greetings = Greeting.view('greeting/all')
67
68 return render("home.html", {
69 "form": form,
70 "greet": greet,
71 "greetings": greetings
72 }, context_instance=RequestContext(request)
73
74 You could notice in this example the `DocumentForm` object.
75 This object works like the ModelForm object but for couchdb
76 documents. Very easy.
77
78 Views/shows/lists are created in _design folder of your application.
79 exemple :
80
81 /yourapp
82 /yourapp/_design
83 /yourapp/_design/views
84 /yourapp/_design/views/viewname
85 /yourapp/_design/views/viewname/map.js
86 ....
87
88 To create databases and sync views, just run the usual `syncdb` command.
89 It won't destroy your datas, just synchronize views.
90 """
91
92 from django.db.models import signals
93
94 -def syncdb(app, created_models, verbosity=2, **kwargs):
98
99 signals.post_syncdb.connect(syncdb)
100