1

I was wondering if anyone knows of a library that resembles the Django DB functionality to replace the standard mysql library?

So; create tables with a model class and access it like you would in a Django projects.

Django makes querying so much easier. I would honestly rather use that in my non-django projects instead of manually joining tables.

As an example, Django allows you to create two tables 'Blog' and 'Author' with a foreign key from Blog to it's Author:

class Author(models.Model):
            name = models.CharField(max_length=128)
            location = models.CharField(max_length=128)    

class Blog(models.Model):
            # Foreign
            author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='blog')

            # Columns
            title = models.CharField(max_length=128)
            content = models.CharField(max_length=6000)
            timestamp = models.DateTimeField(auto_now_add=True)

And, for example, access the author of a specific blog like so:

blog = Blog.objects.filter(id=1)
author = blog.author

And it gets only nicer when you have many-to-many relationships! Clean and simple.

Any recommendations?

New contributor
willer2k is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Please make your question answerable by people who don't know Django, by explaining in details what features you need. – Nicolas Raoul Aug 14 at 1:30
  • 1
    Good point. Thank you. I made the adjustment in the post. – willer2k Aug 14 at 3:10

Your Answer

willer2k is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.