Missing 'help_text' in admin form when showing the back reference for a OneToOne field.
|Reported by:||chris@…||Owned by:||nobody|
|Cc:||admackin+django@…, net147, frankoid||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I'm receiving the following exception in the admin pages for a particular construct:
Caught AttributeError while rendering: 'RelatedObject' object has no attribute 'help_text'
Here's the pastebin for the full exception: http://dpaste.com/564587/
The problem, I believe, is that help_text is missing for the admin screens when attempting to show a "read only" field of an object that was automatically generated from a OneToOneField.
Here's a reduced form of the models and admin pages that cause the error. The application is an art show management software, that has artists, pieces, invoices, and a class called "invoice item" that will attach a piece to an invoice with a price associated. A piece doesnt have a "sale price" until it gets attached to an invoice, a piece can only be on one invoice, but an invoice can have many pieces:
class Piece ( models.Model ): # most detail omitted name = models.CharField ( max_length = 100 ) class Invoice ( models.Model ): # most detail omitted total_paid = models.DecimalField ( max_digits=7, decimal_places=2, blank=True, null=True ) class InvoiceItem ( models.Model ): piece = models.OneToOneField ( Piece ) invoice = models.ForeignKey ( Invoice ) price = models.DecimalField ( max_digits=7, decimal_places=2 ) def __unicode__ ( self ): return "%s for $%s" % ( self.invoice, self.price )
then in admin.py:
class PieceAdmin ( admin.ModelAdmin ): # most detail omitted fields = ( 'artist', 'pieceid', 'name', 'location', 'not_for_sale', 'adult', 'min_bid', 'buy_now', 'voice_auction', 'bidsheet_scanned', 'status', 'top_bid', 'invoiceitem' ) readonly_fields = ( 'top_bid', 'invoiceitem' )
Most of the "fields" relate to fields that were omitted in the models above, or are methods of the PieceAdmin class. Of note is the 'invoiceitem' field. This is a field automatically generated for a Piece because of the OneToOneField field on InvoiceItem. Having this as a "readonly_fields" makes it available to the model (that seems to be a requirement), however, the presence of this at all generates the above exception. This code _did_ work in 1.3. I suspect that help_text is new for 1.4, but not all possible combinations of this or that have had the help_text added. The above is a bit of a corner-case, I know :)
I can probably work around this bug by creating an invoiceitem method (in much the same way I created a top_bid method).
Change History (14)
comment:1 Changed 3 years ago by aaugustin
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted
Changed 2 years ago by admackin@…
Changed 2 years ago by admackin
comment:11 Changed 8 months ago by Tim Graham <timograham@…>
- Resolution set to fixed
- Status changed from new to closed