Overridden fields/widgets for ForeignKeys in ModelForms
|Reported by:||Owned by:||Manuel Saelices|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The docs give the impression one can easily override fields/widgets in ModelForm declarations, but for ForeignKeys that doesn't seem to work.
class Booking(models.Model): ... affiliate = models.ForeignKey(Affiliate, null=True, blank=True, related_name='bookings') ... class BookingForm(forms.ModelForm): affiliate = forms.CharField(max_length=20, required=False, label='Affiliate Code') class Meta: model = Booking fields = ('first_name', 'last_name', 'company', 'email', 'phone', 'mobile', 'adults', 'children', 'affiliate', 'notes')
I need the user to be able to type the 'affiliate' key value straight in without using a dropdown, but using the above approach doesn't attempt to save the affiliate value at all, using r7409. Am I missing something or has this functionality not been catered for?
Change History (10)
comment:7 Changed 9 years ago by
|Owner:||changed from nobody to Manuel Saelices|
|Status:||new → assigned|