django-admin

changing admin site url

给你一囗甜甜゛ 提交于 2021-01-27 08:00:53
问题 Is there a way to change the url to open the admin site in django? I don't want to use the default /admin url. I am new to django so please try giving a bit more detailed information. 回答1: In urls.py, change the line that reads: (r'^admin/(.*)', admin.site.root), to something like: (r'^new_admin/(.*)', admin.site.root), so now instead of http://example.com/admin you'd use http://example.com/new_admin 回答2: Sure, the file urls.py in the root of your project maps URLs to handlers. Just change

Is there an event or another way to call a Javascript function when a Django Admin Popup (the green plus icon) completes?

一世执手 提交于 2021-01-27 06:13:41
问题 Let's imagine we have those Django models: class Band(models.Model): name = models.CharField(max_length=256, default="Eagles of Death Metal") class Song(models.Model): band = models.ForeignKey(Band) When using the admin to manage those models, the band field is associated to a Widget rendered by Django as a select html element. Django's admin also adds a green plus icon next to the select , clicking it opens a pop-up window where the user is presented with the Form to add a new band. When

cannot import name get_user_model

点点圈 提交于 2021-01-27 05:22:41
问题 I use django-registrations and while I add this code in my admin.py from django.contrib import admin from customer.models import Customer from .models import UserProfile from django.contrib.auth.admin import UserAdmin from django.contrib.auth import get_user_model class UserProfileInline(admin.StackedInline): model = UserProfile can_delete = False class UserProfileAdmin(UserAdmin): inlines=(UserProfileInline, ) admin.site.unregister(get_user_model()) admin.site.register(get_user_model(),

How to wrap text in Django admin(set column width)

陌路散爱 提交于 2021-01-27 05:12:08
问题 I have a model Item class Item(models.Model): id = models.IntegerField(primary_key=True) title = models.CharField(max_length=140, blank=True) description = models.TextField(blank=True) price = models.DecimalField(max_digits=12, decimal_places=2, blank=True, null=True) and my model admin class ItemAdmin(admin.ModelAdmin): list_display = ['item_view', 'description', 'item_price', 'seller_view', 'added_on'] actions = ['add_to_staff_picks'] search_fields = ('description', 'title') def item_view

Register custom user model with admin auth

孤街醉人 提交于 2021-01-21 06:22:02
问题 In a Django project, I have a custom user model that adds one extra field: class User(AbstractUser): company = models.ForeignKey(Company, null=True, blank=True) This model is defined in my app, say MyApp.models . How can I get the new User model to show up under "Authentication and Authorization" as the original django.contrib.auth model? 回答1: class User(AbstractUser): class Meta: app_label = 'auth' This can solve your problem but may cause some errors when you migrate your app. The other

Register custom user model with admin auth

一曲冷凌霜 提交于 2021-01-21 06:21:21
问题 In a Django project, I have a custom user model that adds one extra field: class User(AbstractUser): company = models.ForeignKey(Company, null=True, blank=True) This model is defined in my app, say MyApp.models . How can I get the new User model to show up under "Authentication and Authorization" as the original django.contrib.auth model? 回答1: class User(AbstractUser): class Meta: app_label = 'auth' This can solve your problem but may cause some errors when you migrate your app. The other

How to show different inlines depending of current object field value

二次信任 提交于 2021-01-21 04:13:11
问题 Given a model named MainModel and a RelatedModel , where the later has a ForeignKey field to MainModel : class MainModel(models.Model): name = models.CharField(max_length=50) type = models.BooleanField() class RelatedModel1(models.Model): main = models.ForeingKey(MainModel): name = models.CharField(max_length=50) class RelatedModel2(models.Model): main = models.ForeingKey(MainModel): name = models.CharField(max_length=50) and the corresponding ModelAdmin classes: class

How to show different inlines depending of current object field value

爷,独闯天下 提交于 2021-01-21 04:12:10
问题 Given a model named MainModel and a RelatedModel , where the later has a ForeignKey field to MainModel : class MainModel(models.Model): name = models.CharField(max_length=50) type = models.BooleanField() class RelatedModel1(models.Model): main = models.ForeingKey(MainModel): name = models.CharField(max_length=50) class RelatedModel2(models.Model): main = models.ForeingKey(MainModel): name = models.CharField(max_length=50) and the corresponding ModelAdmin classes: class

How to Change the Django 3.1.3 Admin View

房东的猫 提交于 2021-01-07 06:37:50
问题 I am currently working on the Django==3.1.3 version but would like to change the interface like that of the django==3.1 Admin view. The current view looks something like this: I would like to remove the red part and keep the remaining part of the page. 来源: https://stackoverflow.com/questions/65020639/how-to-change-the-django-3-1-3-admin-view

How to Change the Django 3.1.3 Admin View

三世轮回 提交于 2021-01-07 06:36:08
问题 I am currently working on the Django==3.1.3 version but would like to change the interface like that of the django==3.1 Admin view. The current view looks something like this: I would like to remove the red part and keep the remaining part of the page. 来源: https://stackoverflow.com/questions/65020639/how-to-change-the-django-3-1-3-admin-view