Monday, July 29, 2019

Re: Defining Models outside models.py

Hi,

I definitely wouldn't recommend  doing what you want to do, for several reasons:
1. It will be hard to find the model when you need to update it.
2. Django is built with defaults in mind - and when you go outside the defaults you are working against the framework and not with it.

But that being said, you can probably do what you want with the help of the meta options on a django model:

Specifically the app_label property - you should be able to use. The only thing you need to do then is make sure that the file is "loaded" when django starts up somehow.

Regards,

Andréas


Den tors 25 juli 2019 kl 18:58 skrev Sam Taiwo <supersonicboom7@gmail.com>:
Hi everyone,

I know there are currently 3 ways to define a model in Django
1) Define it directly in the models.py file
2) Define it directly in a models package in the same directory as your other app files
3) Define it somewhere completely different and just import the models into the models.py

My question is, is there a way to write a model in any arbitrary file in you directory and link it to your app without having to use models.py file or directory.
For example is there a way to write a model directly in the views file and then add some config to the settings or elsewhere to enable Django to know of it's existence and pick up any changes that happen to it.
I don't mind if it's a complete hack
Thanks

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/95f073eb-8309-4454-8cfd-b190dde90cef%40googlegroups.com.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCfm1%2BOx-_VHaHfgAqeoJ%2BySwvS7T3rnqT4D9KSs%2B%3DwfGg%40mail.gmail.com.

No comments:

Post a Comment