Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6593667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:42:42+00:00 2026-05-25T17:42:42+00:00

I the following in the models.py: class Item(models.Model): date = models.DateField(_(‘date’), blank=True, null=True) description

  • 0

I the following in the models.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)

in the admin.py:

class PaymentItemInline(generic.GenericTabularInline):
    model = PaymentItem
    form = PaymentItemForm

class PaymentAdmin(admin.ModelAdmin):
    inlines = [PaymentItemInline]

in forms.py:

class PaymentItemForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(PaymentItemForm, self).__init__(*args, **kwargs)
        self.fields['credit_account'].label = "Bank Account"

In the PaymentItemInline the label is not changing. I have tried changing other attributes e.g. class which work. If I run through the init in debug mode I can see that the label variable is changing however when the form is rendered the field is still labelled credit account. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:42:42+00:00Added an answer on May 25, 2026 at 5:42 pm

    You’re 98% of the way there. Instead of trying to futz with the form field in __init__, just redefine it in your ModelForm. If you name it the same thing, django will be able to figure out that it is supposed to validate & save to the ForeignKey field. You can use the same formula to change a Field or Widget completely for a given field in a ModelForm.

    You can find the default form field types for each model field type here: https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#field-types

    class PaymentItemForm(forms.ModelForm):
        credit_account = forms.ModelChoiceField(label="Bank Account", queryset=Account.objects.all())
    

    That’s it. No need to override any functions at all : )

    Incidentally, the docs for this field are here: https://docs.djangoproject.com/en/dev/ref/forms/fields/#modelchoicefield

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following models: class Bill(models.Model): date = models.DateTimeField(_(Date of bill),null=True,blank=True) class Item(models.Model):
Assume the following: models.py class Entry(models.Model): title = models.CharField(max_length=50) slug = models.CharField(max_length=50, unique=True) body
I have the following models: class Category(models.Model): name = models.CharField(max_length=40) class Item(models.Model): name =
I have the following models: class Product(models.Model): active = models.BooleanField(default=True) name = models.CharField(max_length=40, unique=True)
I have the following model: class Item(models.Model): unique_code = models.CharField(max_length=100) category_code = models.CharField(max_length=100) label
I have a model such as the following: class Item(models.Model): name = models.CharField(max_length=150) created
I have the following models class Person(models.Model): name = models.CharField(max_length=100) class Employee(Person): job =
I have the following models: class City(models.Model): name = models.CharField(max_length=100) class Pizza(models.Model): name =
i have the following models setup class Player(models.Model): #slug = models.slugField(max_length=200) Player_Name = models.CharField(max_length=100)
I have this simplified model: class Item(models.Model): name = models.CharField(max_length=120) class ItemImage(models.Model): image =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.