Saturday, March 30, 2013

Re: Doubt regarding JSON/SQL in Django

Remember: Premature optimization is the root of all evil.

Use a database for its intended purpose: storing data.

If you use individual files then you need to implement your own locking, writing to disk, caching, and so forth. 

Not only is the database more functional, but it will likely be more performant as well. People have spent decades making databases efficient means of storing data; you aren't likely to improve on that in a few days. :-)

And if some point you want to put the data on one machine and the app server on another, you'll have to deal with remote files as well.

Now, let's talk about this comment: "instead of creating a table in the database for each user" If you have to do that, you're doing it wrong. :-)

Put django.contrib.auth in your INSTALLED_APPS and create this model:

todo/models.py:

class Task(models.Model):
    user = models.ForeignKey(django.contrib.auth.get_user_model())
    description = models.CharField(max_length=200)
    priority = models.PositiveIntegerField(choices=PRIORITY_CHOICES)

and so on. Done. That's really all you need to do to create a task management system with the built-in Django auth. You'll have one table, todo_task, with one row for each Task created by a user.

In a view, you can then do this:

new_task = Task(user=request.user, description=request.POST.description, priority=SOME_PRIORITY).save()

To get all of the tasks for a user:

tasks = Task.objects.filter(user=request.user)

Regards,
-scott

On Saturday, March 30, 2013 9:14:20 AM UTC-4, Parin Porecha wrote:
Hi,

I have just started using Django. I want to create a to-do task
manager application. Users would register, login and can work with
their tasks. So, instead of creating a table in the database for each
user, I want to create a JSON file for each user which will store all
his tasks.

Is there any way I can do this in Django ?
I mean, use the database only for authentication, and use JSON to
store data instead of storing it in the database.

Thanks,
Parin

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment