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を変更しようとしましたが、インラインで2番目のインラインでのみ動作するようです。私はこれがジャンゴの問題かもしれないと感じていますが、私は間違っている可能性があります。今のところ、私はそうするために苦労するほどjavascriptを使ってこれらの変更を行う必要があるように見えます。 – Crazyconoli
おそらくそれは* Djangoの問題ではないでしょう。ここに投稿したコードからは間違いはありませんが、オープンソース、コミュニティレビュー、徹底的にテストされた、大量展開のDjangoソースの前に自分のコードであると確信しています。ただ言って。 –