onyb / reobject

Python without ifs and buts - an ORM layer for Python objects, inspired by Django
Apache License 2.0
81 stars 8 forks source link

How to custom objects Manager? #15

Open agusmakmun opened 3 years ago

agusmakmun commented 3 years ago

from reobject.models.manager import Manager

class ReobjectManager(Manager):

    def get_or_create(self, defaults=None, **kwargs):
        self.model.objects.filter(**kwargs).delete()
        return super().get_or_create(defaults, **kwargs)

class CourseModel(Model):
    course_slug = Field()
    title = Field()
    description = Field()

    objects = ReobjectManager()

But I'm seeing an error:

TypeError: __init__() missing 1 required positional argument: 'model'

when I fill it with objects = ReobjectManager(CourseModel) then it CourseModel not defined.