As per official documentation:
If I look at the source code, they both seem independent classes, each inheriting from the base object
. However, they both seem related in some way, it's just that I am not able to figure out how.
The only relationship I could find is that the Field
class defines a method get_bound_field
. The docstring for this method reads, "Return a BoundField instance that will be used when accessing the form field in a template."
Question: Can you help me figure out the relationship between BoundField
and Form Field
? And in case if it is, how exactly are they different? Or which one to use when?
You declare form fields when defining your form. They are what determine the types and names of the fields, what widgets they use, and what validation they run.
You never create bound fields directly; they are produced - via that method - when you instantiate a form and iterate over its fields. They deal with displaying the field and populating it with any values. The BoundField has an attribute .field
which contains the form field. The relationship is one of composition, not inheritance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With