【发布时间】:2015-07-22 00:53:20
【问题描述】:
我已经检查了this,但我需要连接两个字段中的内容 好的,问题来了。
我有两个模型,brand 和 product,看起来像这样:
品牌模型
class Brand(models.Model):
name = models.CharField(max_length=29)
website = models.URLField()
def __unicode__(self):
return self.name
产品型号
class Product(models.Model):
brand = models.ForeignKey(Brand)
name = models.CharField(max_length=140)
slug = models.SlugField()
def __unicode__(self):
return self.name
管理方法
from .models import Product
@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ('name',)}
模型输入示例:
**Brand**
Name: Example
Website: http://www.example.com
**Product**
Brand: Example (Selection)
Name: Product
Slug: product(prepopulated)
我希望 slug 是 example-product 而不是 product。如何将品牌和名称连接为 slug。
感谢您的帮助。
【问题讨论】:
标签: python django django-models django-admin