how to remove django evolution from admin? - django

How to unregister django-evolution from admin?
admin.site.unregister( something )

Yes admin.site has also an unregister() method, you need to pass it the model class of the admin you want to unregister!
from django_evolution.models import Version, Evolution
admin.site.unregister(Version)
admin.site.unregister(Evolution)
Put it in any module that is loaded on startup after the evolution app, for example in admin.py of an app that comes in INSTALLED_APPS AFTER evolution!

Related

Issue in adding sub-apps in settings.py file

I am unable to add my sub apps like category, user in settings.py. It was working fine but don't know what mistake I have done. Please help. I'm not able to progress from here.
Please create a model and get that model to admin panel.
Link to github
in the admin.py within your "api" folder register the created models so as to display it in the admin panel,
api: admin.py
from django.contrib import admin
from .models import (model created in the models.py)
# Register your models here.
admin.site.register(model created in the models.py)
link to official documentation :
Admin site Official docs

how to hide some models in django grappelli admin?

How to hide some of the models?
I need them registred to be used by other models, while calling via FK or nested etc.
I found one solution which is rather much about view layer of (MVC)
http://blog.jholster.com/post/1534211028/hide-app-names-in-django-admin
I would like to set it in admin.py, that some of registred models are hidden.
If the models are in your application, just don't register them in the first place. If the model is in a third party app like the django.contrib.auth then use AdminSite unregister method. You can put this in any admin.py or urls.py important is to be discovered by the admin.autodiscover.
# admin.py
from django.contrib.auth.models import User
admin.site.unregister(User)

Override the Admin.py file of reusable app in Django

I basically have 2 external Django app that are overriding the UserAdmin model.
Each one of these will first unregister the UserAdmin model and then register their own, something like this:
admin.site.unregister(get_user_model())
admin.site.register(get_user_model(), ExternalAppUserAdmin)
I also, in turn, override the UserAdmin:
admin.site.unregister(get_user_model())
admin.site.register(get_user_model(), MyAppUserAdmin)
The problem is that depending on the order of the INSTALLED_APPS in the settings file only the last app will actually override the UserAdmin.
Most of the times these overriding are just InlineModelAdmin inside the AdminUser, so what I've done so far is to import the external app's InlineModelAdmin models and insert them in my own admin.py. For example:
from relationships.admin import RelationshipInline
....
class BaseProfileAdminStacked( NestedModelAdmin, GuardedModelAdmin):
inlines = [BaseProfileInline, RelationshipInline,]
....
admin.site.unregister(get_user_model())
admin.site.register(get_user_model(), BaseProfileAdminStacked)
But this seems a little hacky to me, because for example:
The first external app will unregister the UserAdmin, then register it again with its own customization
The second external app will do the same, actually overriding the first one
My own app should then import all the AdminInline from the external apps and include them in my own registration of the UserAdmin
Isn't this a waste of effort? Do you have a better idea to do so?

Change app label of groups in Django 1.5

I have extended the User model, but now the new user model is in an app called "account" which gives all models inside this app the app label "account". The Django model "Groups" still has the app label "Auth", so now models which all has something to do with auth is in separate apps in the admin site. Is it possibly to change the app label for "Groups"?
Try this:
from django.db.models.loading import get_models
get_models(django.contrib.auth.models)[1]._meta.app_label = 'group' #or whatever
If you need still more flexibility in the admin you could try django-admin-tools. It makes it easy to reorder and group models in different layouts (tabs, collapsible boxes, etc.) and also add dashboard-like features.
Just in case anyone needs this in Django 3.0+:
from django.apps import apps
apps.get_model('auth', 'Group')._meta.app_label = 'group' #or whatever, but have to be a registered app
Please not that this will mess with django internal model handling, e.g. generate migrations in contrib.auth sitepackage and so on

Django adding tiny-mce

Please suggest the best way to add tinymce to django admin area. Is it possible to add it by extending /admin/change_form.html in my template directory ?
The best way in my opinion is django-tinymce.
Its awesome and super easy to integrate into your project, plus you can add django-filebrowser in easily for image uploading.
django-tinymce is the way to go. You can use pip to install it. You use it on model fields like so:
from tinymce import models as tinymce_models
class Foo(models.Model):
description = tinymce_models.HTMLField(blank=True, null=True, help_text="You can use HTML markup - be careful!")
If you are using South for DB migrations you need to help it out with this line:
add_introspection_rules([], ["^tinymce.models.HTMLField"])
Works like a charm!
Put the tiny_mce.js library somehwere in your media folder. For example in js/tiny_mce/
Then (for django 1.2) you need to create a custom model admin in your_app/admin.py. Add a class Media with js attribute to it. Example:
from django.contrib import admin
from myapp.models import MyModel
class MyModelAdmin(admin.ModelAdmin):
class Media:
js = ('js/tiny_mce/tiny_mce.js',
'js/admin/textareas.js',)
admin.site.register(MyModel, MyModelAdmin)
In media/js/admin/textareas.js you can add your call to tinyMCE.init. Example:
tinyMCE.init({
mode : "textareas",
theme : "advanced"
});
That's it. Javascript is included automatically. No need to overwrite admin templates.
Note: One thing I forget to mention that in this case it only applies to the admin for MyModel. If you need the same functionality for all yout model's, simply register this custom ModelAdmin to them or add Media classes to exising ModelAdmin classes.