Wednesday, December 28, 2016

Re: Define Django Base Model Class

You could monkeypatch django to accomplish this, but I would advise against it.

Instead of having implicit or hidden behaviour you should instruct your developers to use from myproject import models instead of from django.db import models


On Wed, Dec 28, 2016 at 7:13 PM, Guilherme Leal <lealhugui@gmail.com> wrote:
In one of my django projects, I have a base model (that inherits from django.db.models.Model), and is the base model class that all my models uses.
I would like to "override" the base model class from django, so everytime a developer would import the base model class with "from django.db.models import Model", it would insted import my project's custom base model.

The result would be something like this:

from django.db import models

class MyModel(models.Model):
   
pass


>>> type(MyModel)
<class 'MyProject.MyApp.CustomModel'>


Any help would be apreciated!

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/649b3b97-17d3-4257-b473-f050440b4d14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFWa6tJYC3ujmh096Tm9EmfnEixg2Buwa5oRehzMmgLAoUes%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment