I want to override django-oscar Order class which Inheritance from AbstractOrder class (in order apps and abstract_models.py file) but when i try to use migrate & makemigrations commands it says that model there is a problem in register_model function and i have no idea how i can solve it
(i need to use basket_total_incl_tax property and currency field does anyone know where can i find these two in other classes?)
if anyone knows what the problem is and what should i do to solve it please tell me.
thank you.
Related
I would like to change the model name displayed in admin. The idea is to be able to register filtered versions of the model to the admin view. I know that I can add filter options when viewing the model. I am not interested in doing that.
I don't think using the approach for solving admin plural naming is an option: Django fix Admin plural. I could be wrong. If so, please tell me how this can be done.
I found this approach which seems to be the right solutions: Change 'Change model class name' in Django Admin || Change the 'Change' <h1>. However, I can't make it work. Is it just me not trying hard enough?
It is also an option to make a number of models and then register each of them. However, I will prefer to rename and register filtered versions in admin.
Any suggestions for solving this little issue?
I am going to extend the django user models - is it best practice to create a new models.py in my project directory: I.e:
project
application
migrations
static
models.py (all my application specific models)
project
forms.py
urls.py
views.py
*** project models.py ? ***
I want to add email confirmation to my user sign up. So basically just extend the user model. I am thinking this may not be best practice to do in my application models, but for this case it is only going to be one model so would not really matter. However if I want to extend more non-application specific models then it might be better to do this in a separate file?
Does anyone do anything similar and have any tips? Thanks
I don't think putting model inside the project is a food idea, but its practical possible.
For your case I would create an app called utils and put those models there. In real sense i don't think there is non-app specific model . . . correct me if I am wrong.
Plus you can have as many apps as you want
Also you can check post for more
I am thinking of creating some subclassed Django model fields and distributing them as a package on PyPI. I like to write unit tests for my code (à la TDD), but I'm a bit puzzled as to how I'd write tests for this particular library.
The first thought that came to my mind was to create a Django project that makes use of my subclasses and just use the Django test tools, but that doesn't seem very elegant at all. There's got to be a better way!
Is there a method of somehow bootstrapping Django for this type of thing? I'd appreciate someone pointing me in the right direction. Thanks!
Django itself comes with some tests for field-subclassing; the tests have their own models.py where the custom fields are used. You should get the best impression when you have a look at the actual code yourself!
Addition: To have the models defined in your test package being discovered by django you will have to add your yourapp.test package to INSTALLED_APPS.
Django itself has a built-in mechanism for its own tests to be automatically discovered and added to INSTALLED_APPS.
How do I tell django-extensions' shell_plus what models I want to autoload?
In the past whenever shell_plus wasn't autoloading my models it was normally because there was an error in the models and it was causing the autoloading to fail.
If you open shell plus and then try to manually load your modules one at a time what happens?
from app.models import ModelName
Another thing to try is to turn off all of the apps except for the default django apps in the settings file, and see if they autoload just fine. If they do, then slowly add more and more apps, one at a time, until it stops working, then you can find out which model is having issues. Once you know which model is having issues, it will make it easier to find out what is going on.
The most common error I had was a cyclical dependency between two different models (this model depends on that model, but it wasn't loaded yet, and vice versa).
Hope that helps.
shell_plus – An enhanced version of
the Django shell. It will autoload all
your models making it easy to work
with the ORM right away.
Quote from django-extensions github wiki located https://github.com/django-extensions/django-extensions/wiki/Current-Command-Extensions
Don't believe its actually changeable its designed to quickly autoload ALL models.
I've made a new patch for the shell_plus extension that makes it possible to ignore some models. Waiting for https://github.com/django-extensions/django-extensions/pull/99 to get accepted.
according to the code. shell_plus always loading all your models.
By default shell_plus always loads all your models.
Thanks to #xeor you can use the option SHELL_PLUS_DONT_LOAD in your settings to skip some of your models.
You can also configure aliases to your models to avoid names collisions.
More details:
http://django-extensions.readthedocs.org/en/latest/shell_plus.html?highlight=shell_plus#configuration
Talking about Django 1.1.1. I thought at one time (0.96) the kinds of things put inside of the admin.py file were part of an inner class of the model.
There's a certain beauty in having all of this in one place. But I don't know if this change was out of necessity. Any compelling reasons one way or the other?
They took away that particular magic, but there is nothing to keep you from putting your admin.ModelAdmin subclass right after the models.Model subclass itself. I prefer keeping them together myself because it's less likely I'll forget to add a field to the list to show in the admin display.
Perhaps it would not be a good idea to have this stuff in the models anyway, since it would be excess information when using the site as a non-admin? (For performance reasons)
There isn't any way to express the admin options inside the model definition as an inner class in the latest version. But there is no reason why you can't put your ModelAdmin class right after your Model class in your models.py file. You can then just call your admin.site.register() right after your definition.
You may run into a problem with the register() being called more than once for a model, which will generate an error. models.py should only get loaded once though so this should work. If not, you can definitely declare your ModelAdmin class in models.py, and then put all your register() calls in admin.py.
A couple reasons that I can think of to put it them in admin.py are:
Convention -- seems like this is becoming a best practice.
Decoupling -- the admin definitions don't really have much to do with the model.
Cleanness -- probably no need to fill up your models.py file with stuff you aren't going to change much.
But if your models.py file isn't going to be very long I can see the attraction of having them right next to each other.
use class Admin inside your models as u use class Meta
and then define what u want