I하여 models.py에 다음 사항 admin.py에서레이블 변경 일반 인라인 관리
class Item(models.Model):
date = models.DateField(_('date'), blank=True, null=True)
description = models.CharField(_('description'), max_length=255)
content_type = models.ForeignKey(ContentType, verbose_name=_('content type'))
object_id = models.PositiveIntegerField(_('object id'), db_index=True)
object = generic.GenericForeignKey('content_type', 'object_id')
class ItemAccountAmountRef(Item):
""" Items of which a Quote or an Invoice exists. """
amount = models.DecimalField(max_digits=10, decimal_places=2)
reference = models.CharField(max_length=200)
debit_account = models.ForeignKey(Account, related_name='receivables_receipt_debit_account')
credit_account = models.ForeignKey(Account, related_name='receivables_receipt_credit_account')
class PaymentItem(ItemAccountAmountRef):
pass
class Payment(models.Model):
invoice = models.ManyToManyField(Invoice, null=True, blank=True)
date = models.DateField('date')
attachments = generic.GenericRelation(Attachment)
site = models.ForeignKey(Site, related_name='payment_site', null=True, blank=True
items = generic.GenericRelation(PaymentItem)
:
forms.py에서class PaymentItemInline(generic.GenericTabularInline):
model = PaymentItem
form = PaymentItemForm
class PaymentAdmin(admin.ModelAdmin):
inlines = [PaymentItemInline]
:
class PaymentItemForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(PaymentItemForm, self).__init__(*args, **kwargs)
self.fields['credit_account'].label = "Bank Account"
에서 PaymentItemInline 레이블이 변경되지 않습니다. 다른 속성을 변경하려고했습니다. 작동하는 클래스. 디버그 모드에서 init을 실행하면 레이블 변수가 변경되는 것을 볼 수 있지만 양식이 렌더링 될 때 필드는 여전히 신용 계정으로 표시됩니다. 어떤 제안?
가 브라우저 캐시를 삭제 한? – Pannu
예. 그래도 여전히 같은 결과가 슬프게 나옵니다. 다른 모델에서는 이제 외래 드롭 다운의 onclick을 변경하려고 시도했지만 두 번째 인라인에서만 작동하는 것으로 보입니다. 나는 이것이 장고 문제일지도 모른다는 느낌이 들지만 나는 틀릴 수있다. 지금 당장은 자바 스크립트를 통해 이러한 변경 작업을 수행해야하는 것처럼 보입니다. – Crazyconoli
"장고 문제"가 아닌가? 여기에 오류가있는 코드를 게시 한 것은 분명하지 않지만 오픈 소스, 커뮤니티 검토, 철저한 테스트 및 대량 배포 Django 소스 이전에는 코드가 될 것이라고 확신합니다. 그냥 말해. –