【发布时间】:2011-09-23 00:03:24
【问题描述】:
除了这个例子,我找不到任何人这样做的一个例子,除了知道代码需要放在哪里之外,这对我没有帮助。
How to prepopulate UserProfile fields in the Django admin?
这是我的代码
class QuoteMaterial(models.Model):
name = models.CharField(_('name'), max_length=255)
content = models.TextField(_('content'),
help_text=_('A static priced item used when doing a job. Selectable when creating a quote. '))
price = models.DecimalField(_('price'), max_digits=6, help_text="not sure if this is before or after VAT yet", decimal_places=2, default="0.00")
def get_companies():
return CompanyProfile.objects.filter(user=request.user)
company = models.ForeignKey(CompanyProfile, default=get_companies)
如果不明显,我尝试在管理部分使用属于已登录用户的可用公司填充下拉列表。
我的问题是我不知道如何将请求对象传递给“get_companies”。任何人都知道任何例子。
【问题讨论】:
标签: python django django-admin