mysql - Multiple individual users on one database -


i have .sql database interact using django . database in beginning filled public data can accessed anynone. multiple individual users can add rows table(private data). how can user see changes made in database(private data)?

i assume you're using django.contrib.auth. need like:

from django.contrib.auth.models import user  # ...  class privatedata(models.model):     # ... private data fields ...     user = models.foreignkey(user) 

then can user's fields with:

privatedata.objects.filter(user=request.user) 

edit: so, if users ip addresses, , you're not using login mechanism, don't need django.contrib.auth... though it's have anyway since can use authenticate yourself , use built-in admin stuff manage site.

if want tie data ip addresses, set ipuser model:

class ipuser(models.model):     address = models.charfield(max_length=64, unique=true) # big enough ipv6     # add whatever other discrete (not list) data want store address.  class privatedata(models.model):     # ... private data fields ...     user = models.foreignkey(ipuser) 

the view function looks like:

def the_view(request):     remoteaddr = request.meta['remote_addr']     try:         theuser = ipuser.objects.get(address=remoteaddr)     except ipuser.doesnotexist:         theuser = ipuser.objects.create(address=remoteaddr)     usermodifieddata = privatedata.objects.filter(user=theuser) 

one thing note: when you're testing manage.py runserver, you'll need specify ip address via environment variable:

$ remote_addr=127.0.0.1 manage.py runserver 

when use django real web server apache, server set variable you.

there several ways optimize this, should started.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -