Toolchain/frameworks
I'm using django==2.1.3
and python-cloudant==2.1.3
and running CouchDB ver. 2.2.0
, and pretty much doing all of my setup/configuration through Fauxton
. I like to think that I know my way around python/django in general, and I'm testing this approach in a small little project to see how it works
Problem Description
Suppose I have a fairly simple CRUD application with just 1 model:
class Asset(models.Model):
asset_id = models.CharField(max_length=32)
asset_name = models.CharField(max_length=32)
and I have a view that I use to create the asset
class CreateAssetView(views.View):
def get(self, request, *args, **kwargs):
#some code here
def post(self, request, *args, **kwargs):
#some code here|
#log request data into database
client = CouchDB('myusername', 'mypassword', url='http://127.0.0.1:5984', connect=True)
db = client['assets']
log_data = {'view_name': self.view_name, 'post_data': post_data,'user': request.user.username,
'time': str(timezone.now())}
db.create_document(log_data)
return render(...)
I understand that I should be doing the logging portion using a middleware (which I plan to) and probably just use django's CreateView
in that case, I'm doing this approach for now just during early development.
What I'm having a problem wrapping my head around is creating a user with myusername
and mypassword
that has the permissions to:
- Write new documents
- Read old documents
- not edit already created documents
I could even settle for 1 and 3 only (and only use admin to read). I spent a little bit of time playing around with Fauxton
's interface for permissions, but I can only basically create a user
and assign a role
(couldn't even get to assigning a password :/)
clarification
The Asset
is not a CouchDB
document, that's a normal SQL model, I only want to dump the logs with post data to CouchDB
Any help/gudiance/documentation pointers would be really appreciated