Wednesday, December 28, 2016

Re: Define Django Base Model Class

That doesn't change the advise

I would find it weird to import a class only to have something else loaded


"Explicit is better than implicit."


On Wed, Dec 28, 2016 at 3:02 PM, Guilherme Leal <lealhugui@gmail.com> wrote:
Got it.

The custom model doesn't have any significantly different behaviour, just some helper properties that return, for instance, a basic GrapQL Node from that very model (the project uses graphene).

2016-12-28 15:46 GMT-02:00 Avraham Serour <tovmeod@gmail.com>:
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.

--
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/CAOs3Lp57Kwtoj8xJ6t1mwfaUv41RW%2BrBTozxbiyuAV3h9et5-g%40mail.gmail.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/CALn3ei2%3DEMQ%3D7Y5Ja8%2BpWOCZ3C%2Ba9zjvTNY8WouRUTPeNNadxg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment