Forms#
The transactions app ships two forms: the main transaction
create / edit TransactionForm and the secondary
PostClosedOrClosingTransactionForm shown when closing a
transaction implicitly closes parent transactions or stakings.
TransactionForm#
ModelForm for Transaction.
Constructed with the current user: the item queryset is
limited to that user’s items, the parents queryset to that
user’s transactions (newest first), and most fields receive
either a validator (currency must be 3 alpha chars,
price and fee must be >= 0) or help text.
Two extras layered on top of the model:
An
attachmentsfield (MultipleFileField) that lets the user attach / remove files alongside the transaction record.save()materializes each uploaded file as anAttachmentrow.The
targetfield accepts either a plain numeric price or a percentage with a trailing%;clean_target()enforces that regex.
The form-level clean() performs the
cross-field validation:
Coin transactions must have an
exchangeselected.A transaction marked
is_depositcannot also beis_closing.Only negative-amount transactions can be
is_closing.Marking
is_closedoris_closingrequires aclosed_ondate.Sell (negative-amount) transactions must have at least one
parentsentry.
PostClosedOrClosingTransactionForm#
Secondary follow-up form rendered by
PostClosedOrClosingTransactionUpdateFormView
after a user closes a transaction whose chain of parent
transactions and / or related stakings can be closed in the
same gesture. It carries two optional fields:
parents– the parent transactions to mark as closed.stakings– the related staking records to mark as sold.
Both querysets are passed in from the view.