Re: [Forms] Avoiding Repetition
Andre, you're right. But a subclass would probably save me one line: model = OrderItem The rest follows a pattern but is otherwise unique. I'm going to look into dynamic forms as suggested by Derek On Tue, Jun 21, 2011 at 5:42 PM, Andre Terrawrote: > I'm reading this on my phone, so I apologize in advice if I missed > something crucial, but what's stopping you from subclassing and > overriding just the relevant parts? > > Sincerely, > Andre Terra > > On 6/17/11, Nikhil Somaru wrote: > > Hi, > > > > Is there a way to reduce the repetition in the following form classes: > > > > class ItemsStep2(ModelForm): #approval > > class Meta: > > model = OrderItem > > fields = ('item', 'quantity_requested', 'quantity_approved') > > widgets = { > > 'quantity_requested': > TextInput(attrs={'readonly':'readonly'}) > > } > > > > > > class ItemsStep3(ModelForm): #ship > > class Meta: > > model = OrderItem > > fields = ('item', 'quantity_requested', 'quantity_approved') > > widgets = { > > 'quantity_requested': > TextInput(attrs={'readonly':'readonly'}), > > 'quantity_approved': TextInput(attrs={'readonly':'readonly'}) > > } > > > > > > class ItemsStep4(ModelForm): #confirm receipt > > class Meta: > > model = OrderItem > > fields = ('item', 'quantity_requested', 'quantity_approved', > > 'quantity_received') > > widgets = { > > 'quantity_requested': > TextInput(attrs={'readonly':'readonly'}), > > 'quantity_approved': TextInput(attrs={'readonly':'readonly'}) > > } > > > > > > class ItemsStep5(ModelForm): #order summary > > class Meta: > > model = OrderItem > > fields = ('item', 'quantity_requested', 'quantity_approved', > > 'quantity_received') > > widgets = { > > 'quantity_requested': > TextInput(attrs={'readonly':'readonly'}), > > 'quantity_approved': > TextInput(attrs={'readonly':'readonly'}), > > 'quantity_received': > TextInput(attrs={'readonly':'readonly'}), > > } > > > > The model that uses these forms has a ForeignKey (Order hasMany > OrderItems) > > to an associated model that has a attribute "step" (order_instance.step) > > which determines the class above to use (this code is in views) > > > > Thanks in advance. > > -- > > Yours, > > Nikhil Somaru > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Django users" group. > > To post to this group, send email to django-users@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > For more options, visit this group at > > http://groups.google.com/group/django-users?hl=en. > > > > > > -- > Sent from my mobile device > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Yours, Nikhil Somaru -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: [Forms] Avoiding Repetition
I'm reading this on my phone, so I apologize in advice if I missed something crucial, but what's stopping you from subclassing and overriding just the relevant parts? Sincerely, Andre Terra On 6/17/11, Nikhil Somaruwrote: > Hi, > > Is there a way to reduce the repetition in the following form classes: > > class ItemsStep2(ModelForm): #approval > class Meta: > model = OrderItem > fields = ('item', 'quantity_requested', 'quantity_approved') > widgets = { > 'quantity_requested': TextInput(attrs={'readonly':'readonly'}) > } > > > class ItemsStep3(ModelForm): #ship > class Meta: > model = OrderItem > fields = ('item', 'quantity_requested', 'quantity_approved') > widgets = { > 'quantity_requested': TextInput(attrs={'readonly':'readonly'}), > 'quantity_approved': TextInput(attrs={'readonly':'readonly'}) > } > > > class ItemsStep4(ModelForm): #confirm receipt > class Meta: > model = OrderItem > fields = ('item', 'quantity_requested', 'quantity_approved', > 'quantity_received') > widgets = { > 'quantity_requested': TextInput(attrs={'readonly':'readonly'}), > 'quantity_approved': TextInput(attrs={'readonly':'readonly'}) > } > > > class ItemsStep5(ModelForm): #order summary > class Meta: > model = OrderItem > fields = ('item', 'quantity_requested', 'quantity_approved', > 'quantity_received') > widgets = { > 'quantity_requested': TextInput(attrs={'readonly':'readonly'}), > 'quantity_approved': TextInput(attrs={'readonly':'readonly'}), > 'quantity_received': TextInput(attrs={'readonly':'readonly'}), > } > > The model that uses these forms has a ForeignKey (Order hasMany OrderItems) > to an associated model that has a attribute "step" (order_instance.step) > which determines the class above to use (this code is in views) > > Thanks in advance. > -- > Yours, > Nikhil Somaru > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- Sent from my mobile device -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: [Forms] Avoiding Repetition
Thanks derek. On Sat, Jun 18, 2011 at 8:03 AM, Nikhil Somaruwrote: > Hi, > > Is there a way to reduce the repetition in the following form classes: > > class ItemsStep2(ModelForm): #approval > class Meta: > model = OrderItem > fields = ('item', 'quantity_requested', 'quantity_approved') > widgets = { > 'quantity_requested': TextInput(attrs={'readonly':'readonly'}) > } > > > class ItemsStep3(ModelForm): #ship > class Meta: > model = OrderItem > fields = ('item', 'quantity_requested', 'quantity_approved') > widgets = { > 'quantity_requested': TextInput(attrs={'readonly':'readonly'}), > 'quantity_approved': TextInput(attrs={'readonly':'readonly'}) > } > > > class ItemsStep4(ModelForm): #confirm receipt > class Meta: > model = OrderItem > fields = ('item', 'quantity_requested', 'quantity_approved', > 'quantity_received') > widgets = { > 'quantity_requested': TextInput(attrs={'readonly':'readonly'}), > 'quantity_approved': TextInput(attrs={'readonly':'readonly'}) > } > > > class ItemsStep5(ModelForm): #order summary > class Meta: > model = OrderItem > fields = ('item', 'quantity_requested', 'quantity_approved', > 'quantity_received') > widgets = { > 'quantity_requested': TextInput(attrs={'readonly':'readonly'}), > 'quantity_approved': TextInput(attrs={'readonly':'readonly'}), > 'quantity_received': TextInput(attrs={'readonly':'readonly'}), > } > > The model that uses these forms has a ForeignKey (Order hasMany OrderItems) > to an associated model that has a attribute "step" (order_instance.step) > which determines the class above to use (this code is in views) > > Thanks in advance. > -- > Yours, > Nikhil Somaru > > -- Yours, Nikhil Somaru -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
[Forms] Avoiding Repetition
Hi, Is there a way to reduce the repetition in the following form classes: class ItemsStep2(ModelForm): #approval class Meta: model = OrderItem fields = ('item', 'quantity_requested', 'quantity_approved') widgets = { 'quantity_requested': TextInput(attrs={'readonly':'readonly'}) } class ItemsStep3(ModelForm): #ship class Meta: model = OrderItem fields = ('item', 'quantity_requested', 'quantity_approved') widgets = { 'quantity_requested': TextInput(attrs={'readonly':'readonly'}), 'quantity_approved': TextInput(attrs={'readonly':'readonly'}) } class ItemsStep4(ModelForm): #confirm receipt class Meta: model = OrderItem fields = ('item', 'quantity_requested', 'quantity_approved', 'quantity_received') widgets = { 'quantity_requested': TextInput(attrs={'readonly':'readonly'}), 'quantity_approved': TextInput(attrs={'readonly':'readonly'}) } class ItemsStep5(ModelForm): #order summary class Meta: model = OrderItem fields = ('item', 'quantity_requested', 'quantity_approved', 'quantity_received') widgets = { 'quantity_requested': TextInput(attrs={'readonly':'readonly'}), 'quantity_approved': TextInput(attrs={'readonly':'readonly'}), 'quantity_received': TextInput(attrs={'readonly':'readonly'}), } The model that uses these forms has a ForeignKey (Order hasMany OrderItems) to an associated model that has a attribute "step" (order_instance.step) which determines the class above to use (this code is in views) Thanks in advance. -- Yours, Nikhil Somaru -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.