doableware / djongo

Django and MongoDB database connector
https://www.djongomapper.com
GNU Affero General Public License v3.0
1.88k stars 355 forks source link

SchemaLess Djongo #281

Open luisfmelo opened 5 years ago

luisfmelo commented 5 years ago

One line description of the issue

I want to have shcema-less models.

Python script

So, my Blog model s defined as:


class Blog(models.Model):
    name = models.CharField(max_length=100)
    tagline = models.TextField()

    objects = models.DjongoManager()

And I want to create a Blog instance with an extra field named author:

blog = Blog(
            name='Hello MongoDB!',
            tagline='Just wanted to drop a note from Django. Cya!',
            author='mongodb'
        )

But when I try, I see: Blog() got an unexpected keyword argument 'author'

thestick613 commented 5 years ago

There is no way to have a schema-less model in djongo.

Raznak commented 5 years ago

Hello,You can set the enforce_schema propertie to True in the database settings Le 8 juin 2019 21:20, Luís Melo notifications@github.com a écrit :One line description of the issue I want to have shcema-less models. Python script So, my Blog model s defined as:

class Blog(models.Model): name = models.CharField(max_length=100) tagline = models.TextField()

objects = models.DjongoManager()

And I want to create a Blog instance with an extra field named author: blog = Blog( name='Hello MongoDB!', tagline='Just wanted to drop a note from Django. Cya!', author='mongodb' )

But when I try, I see: Blog() got an unexpected keyword argument 'author'

—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.

AliMirlou commented 5 years ago

One line description of the issue

I want to have shcema-less models.

Python script

So, my Blog model s defined as:


class Blog(models.Model):
    name = models.CharField(max_length=100)
    tagline = models.TextField()

    objects = models.DjongoManager()

And I want to create a Blog instance with an extra field named author:

blog = Blog(
            name='Hello MongoDB!',
            tagline='Just wanted to drop a note from Django. Cya!',
            author='mongodb'
        )

But when I try, I see: Blog() got an unexpected keyword argument 'author'

Try: blog = Blog.objects.mongo_insert_one({'name': 'Hello MongoDB!', 'tagline': 'Just wanted to drop a note from Django. Cya!', 'author': 'mongodb'})

It tunnels directly through pymongo module and inserts a schema less document.