我希望将ModelA显示为TabularInline of ModelB,同时希望使用Django简单历史模块维护ModelA更改的历史。
有办法这样做吗?查看了TabularInline和Django simpleHistory的正式文档,但无法从中获得更多信息。
模式A
class ModelAInline(admin.TabularInline):
model = ModelA
def has_add_permission(self, request, obj=None):
return False
B型
class ModelBAdmin(admin.
抱怨在使用TabularInline时缺少list_display。我想为我的子模型添加排序。我使用了SortableAdminMixin类和admin.TabularInline,但是admin.TabularInline没有为SortableAdminMixin指定合适的字段。当我尝试编写list_display = "__all__"时,在使用TabularInline时没有发生任何关于缺少list_display的问题 from adminsortable2.admin import SortableAdminMixin
class ProjectStepInlin
我一直在文档和stackoverflow/论坛中寻找一种方法,当我在django admin中保存模型时,可以忽略模型的内联子模型。我已经找了几天了,但似乎找不到答案。
我有一个普通的tabularinline对象:
class UserOrdersAdmin(admin.TabularInline):
model = Order
classes = ['collapse']
和普通用户管理员注册:
class UserAdmin(BaseUserAdmin):
inlines = (UserOrdersAdmin, UserSettingsAdmin)
我有以下模型和TabularInline子类:
class SomeModel(models.Model):
name = models.CharField(max_length=50)
class SomeModelInline(admin.TabularInline):
model = SomeModel
class SomeOtherModelAdmin(admin.ModelAdmin):
inlines = [SomeModelInline]
在没有显式指定TabularInline的字段的情况下,Django的admin显示了字段"id“和
我试图使用下面的代码将自定义字段添加到InlineFormset中,但是字段不会出现在Django管理中。InlineFormset是否太过锁定,不允许这样做?我的打印"ding“测试会像预期的那样触发,我可以打印出form.fields并在那里看到它们,但是实际的字段从未呈现在管理程序中。
admin.py
from django.contrib import admin
import models
from django.forms.models import BaseInlineFormSet
from django import forms
from forms import
我已经附加了FoobarAdmin中的TestInline,这件事运行良好,但我希望登录的用户是预先填充的added_by字段
from django.contrib import admin
from django.contrib.auth.models import User
class Test(models.Model):
description = models.TextField()
added_on = models.DateTimeField(auto_now_add=True)
added_by = models.ForeignKey(User,
我正在使用Django1.2的新ManyToMany admin.TabularInline来显示管理应用程序中的相关对象,它工作得很好,只是我不知道如何设置"ordering“属性,以便它可以按交叉引用的字段名称进行排序。
例如:
class Foo(models.Model):
name = models.CharField(max_length=100)
class Bar(models.Model):
title = models.CharField(max_length=100)
foos = models.ManyToManyField(Foo)
我遵循了django docs starter应用程序,并使用django.auth添加了一个登录和注册系统。我希望使它,使用户谁已经登录可以创建一个新的投票,并链接到问题的选择自动。就像在django管理面板中一样(见图)。
在admin.py中,您使用admin.TabularInLine和字段集,但我不确定在forms.py或views.py中如何才能真正做到这一点。我似乎在文档或其他任何地方找不到太多,所以如果有人可以获得,那就太好了。
admin.py
from django.contrib import admin
from .models import Question, Cho
我有两个Django模型被一个外键连接:
class Author(models.Model):
...
class Book(models.Model):
author = models.ForeignKey(Author)
请考虑下面的管理示例(我想做的正好相反):
from django.contrib import admin
from my_app.models import Author, Book
class BookInline(admin.TabularInline):
model = Book
class AuthorAdmin(admin.M
对于TaskInline,如果有超过5个元素,我想显示它:
from django.contrib import admin
from django.contrib.auth.models import User
from django.db import models
class Task(models.Model):
title = models.CharField(max_length=50)
description = models.TextField()
performer = models.ForeignKey(User, on_delete=model
假设我想上三个这样的课程:
class Book(models.Model):
# ...
class Author(models.Model):
# ...
class BookAuthor(models.Model):
book = models.ForeignKey(Book)
author = models.ForeignKey(Author)
我想要的是能够从Book模型的管理面板中添加(并查看所添加的)。-我怎么能在Django做这个?
我认为这样做的优雅方法是在不同的应用程序中实现视图。但是这个项目只会被管理员用作数据收集工具。因此,我不想实现
我正在通过TabularInline在Django的管理中列出一个模型。在这个内联中,我想使用Django的模型遍历语法来列出通过外键从这个模型引用的其他模型中的数据。例如:
class MyRelatedModel(models.Model):
name = models.CharField(max_length=50)
created = models.DateField(auto_now_add=True)
other = models.ForeignKey('MyOtherRelatedModel')
class MyOtherRelatedM
请帮助理解如何在Django管理Person实例中显示组列表,在本例中:
class Person(models.Model):
name = models.Charfield(max_length=120)
class Group(models.Model):
title = models.Charfield(max_length=120)
persons = models.ManyToManyField(Person)
我有两个模特:
Python 3.7
class ClassOne(models.Model):
name = models.CharField(max_length=10, default='')
class ClassTwo(models.Model):
name = models.CharField(max_length=20, default='')
class_ones = models.ManyToManyField(ClassOne)
现在,我想展示ClassOne在django-管理与所有ClassTwo的列表。我
我的Django模型如下:
class Page(models.Model):
title = models.CharField(max_length=200)
class Section(models.Model):
page_id = models.ForeignKey(Page)
title = models.CharField(max_length=200)
class SubSection(models.Model):
section_id = models.ForeignKey(Section)
title = models.CharFi
在Django的管理中,内联显示了一个相当简单的外键关系:
# models
class Profile(models.Model):
name = models.CharField(max_length=30)
class EmailAddress(models.Model):
address = models.EmailField()
is_default = models.BooleanField()
# admins
class ProfileAdmin(admin.ModelAdmin):
class EmailAddressInline(admi
我最近扩展了UserProfile,所以我的admin.py看起来像这样:
from django.contrib import admin
from django.contrib.auth.models import User
from models import UserProfile
from django.contrib.auth.admin import UserAdmin
admin.site.unregister(User)
class UserProfileInline(admin.StackedInline):
model = UserPr
我有一组模型,看起来像这样:
class Page(models.Model):
title = models.CharField(max_length=255)
class LinkSection(models.Model):
page = models.ForeignKey(Page)
title = models.CharField(max_length=255)
class Link(models.Model):
linksection = models.ForeignKey(LinkSection)
text = models.CharFi
我正在尝试使用在Django管理中显示缩略图。
我的models.py已经按照文档使用了sorl.thumbnail.ImageField:
Note You do not need to use the sorl.thumbnail.ImageField to use sorl.thumbnail. The standard django.db.models.ImageField is fine except that using the sorl.thumbnail.ImageField lets you plugin the nice admin addition explained i
我有一个外键模型Group的模型Word,我希望django管理面板中的结构是嵌套的,如下所示:
-Group
-Word1 (clickable where I can show all the info about this word model)
-Word2 (clickable)
-Word3 (clickable)
我尝试在admin.py中做这样的事情,但得到了一个错误:没有类元
from django.contrib import admin
from main_app.models import Profile, Project, User, Word, Phrase,
我已经对管理表单做了一些更改,以便可以像CharField一样显示TextField,但表单本身在管理菜单中看起来相当丑陋,因为表单元素不能正常伸展。我也不想在打印时显示模型的名称,因为它已经在页面上了。我该如何做出这些改变呢?理想情况下,我希望链接字段占据所有剩余空间,如下面的截图所示。
admin.py
from linkrotator.models import Link, LinkList
from django.contrib import admin
from django import forms
class LinkModelForm( forms.ModelForm ):