我正在试着写一个BookApp。每次我创建一本新书时,它都会在选择中加载前一本书的章节字段。如何移除关系,但不删除内容。我还包括了一些图片。
#models.py
from django.db import models
class Category(models.Model):
name = models.CharField(max_length=250)
def __str__(self):
return self.name
class Author(models.Model):
name = models.CharField(max_length=250)
堆栈上的各种其他帖子都研究了如何在list_display中“适当地”包含外键,从而支持排序等。
然而,我对此不感兴趣。我只想显示外键字段的unicode。
来自django文档:
A few special cases to note about list_display:
If the field is a ForeignKey, Django will display the __unicode__() of the related object.
我之前已经让它工作了,但是自从我最后一次检查django admin以来,如果list_display包含一个外键字段,它就不再显示任何条
在Django管理中,我可以使用内联地显示泛型关系的反面。这很管用..。
class Art(TimeDateStampedModel):
collections = GenericRelation('apps.Collection')
admin.py
class CollectionsInline(GenericTabularInline):
model = Collection
class ArtAdmin(admin.ModelAdmin):
inlines = [
CollectionsInline,
我刚刚启动了一个新的Django项目,我希望创建自己的客户用户模型,而不是使用默认的用户模型。除了我添加了更多的字段,date_of_birth被称为‘道布’而不是必需的,我基本上遵循了2.1文档(我的Django版本)中的内容。但是当我创建超级用户帐户时,我无法登录到管理面板。上面写着:“请为一个职员帐户输入正确的电子邮件地址和密码。请注意,这两个字段都可能区分大小写。”
这是我的代码:
用户/Models.py
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, Base
嗨,朋友们,我想用其他表(结构)中的字段扩展用户模型,作为外来密钥。在创建超级用户之后,我将向您展示我的模型和错误。
from django.db import models
from django.contrib.auth.models import User
from immob.models import structure
from django.db.models.signals import post_save
from django.dispatch import receiver
class Profile(models.Model):
User = models.
我有以下代码:
class Item(models.Model):
name = models.CharField(max_length=100)
keywords = models.CharField(max_length=255)
type = models.ForeignKey(Type)
class Meta:
abstract = True
class Variant(models.Model):
test_field = models.CharField(max_length=255)
class Product(Ite
因此,我是Python和Django的新手,下面是Vitor链接的教程:
我将这段代码复制到models.py中
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class Board(models.Model):
name = models.CharField(max_length=30, unique=True)
description = models.CharField(max_length=100)
class
我在我的应用程序中使用django+jquery自动完成小部件。我定制了一个表的管理表单,以便在输入文本框中自动完成。它正在工作,只是当我保存表单时,会出现以下异常:
ValueError at /admin/Stock/venta/add/
Cannot assign "u'Agua'": "Venta.producto" must be a "Producto" instance.
Request Method: POST
Request URL: http://127.0.0.1:8080/admin/Stock/ve
我正在尝试实现InlineModels,但我收到了错误消息。你能帮帮我吗?谢谢你。
myproject.api.models
from django.db import models
from django.contrib.auth.models import User
from myproject.song.models import Album, Song, Artist
class UserLibrary(models.Model):
user = models.ForeignKey(User)
myproject.api.admin.py
from django.contri
我无法显示我的自定义对象“状态”。我可以把它填满,然后在我的管理中看到它。但是,当我尝试用HTML获取它时,它不起作用。然而,它确实显示用户名,姓氏等。
这是我的model.py (在帐户中):
from django.contrib.auth import models as authmodels
class UserZ(authmodels.User,authmodels.PermissionsMixin):
status = models.CharField(max_length=100, blank=True)
avatar = models.ImageField(u
我正在尝试扩展Django用户模型以包含另一个字段。正如文档中所述,我扩展了该字段,如下所示:
class Employee(models.Model):
# This field is required.
user = models.OneToOneField(User)
manager_id = models.ForeignKey(User, related_name='employees')
我希望manager_id是自引用的,并与用户相关(而不是定义一个新的经理表),只需在常规用户页面中显示新字段。为此,按照文档中的说明,我还添加了以下内
我有一个模型,其字段是日期和另一个模型文本字段的外键:
# models.py
class Publications(models.Model):
"""A class for daily article publications"""
date = models.DateField(
help_text="date for this article to be published"
)
headline = models.ForeignKey(
Articles,
假设我有这些模型作为一个简单的例子:
class Event(models.Model):
name = models.CharField(max_length=50, default='')
app = models.ForeignKey(App)
class App(models.Model):
name = models.CharField(max_length=50, default='')
app_config = models.ForeignKey(AppConfig)
class AppConfig(models
我不知道为什么在尝试访问change_list模型的admin mymodel页面时出现了这个错误:
NoReverseMatch at /admin/myapp/mymodel/
Reverse for 'myapp_mymodel_change' with arguments '(u'',)' and keyword arguments '{}' not found.
Error during template rendering
In template /usr/local/lib/python2.7/dist-packa
travelers.models
from django.db import models
class ShortInfoTraveler(models.Model):
name = models.CharField(max_length=200, blank=True)
email = models.EmailField(blank=True)
blogs.models
from django.db import models
from travelers.models import ShortInfoTraveler
class Title(models.M
为了将信息添加到我的auth.User模型中,我遵循了这个。我想将一个用户链接到一个协会(例如,假设一个用户是一个客户端)和这个社会中的一个工作。下面是我的代码:
societies/models.py:
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
class UserProfile(models.Model):
"""
Stores the user in
我目前在我的Role表中有4个条目,这些条目引用了网站中用户的角色。可以在复选框列表中选择这些角色,但我无法保存通过表单提交的数据。我得到以下错误:'RegisterForm' object has no attribute 'roles'** in forms.py。
我在这里错过了什么?
以下是代码:
forms.py
from django import forms
from django.contrib.auth.forms import UserCreationForm
from .models import User, Profile, Role
我的网站有两种类型的用户:客户和供应商。我的课堂结构如下:
class Customer(models.Model):
# stuff specific to customers
class Supplier(models.Model):
# stuff specific to suppliers
class Profile(models.Model): # returned by Django's User.get_profile()
user = models.ForeignKey(User, unique=True)
customer = m
我有一个Profile模型,它与User模型有OneToOne关系。我还有一个Group模型,它将users字段作为ManyToMany到User。
我正试图在Django Admin中实现一件简单的事情:能够创建一个有一些新用户的组,并允许为这些新用户填写一些配置文件字段。
我试了几件事
class ProfileInline(admin.StackedInline):
model = Profile
class UserInline(admin.StackedInline):
model = Group.users.through
inlines = [ Prof