Created
August 9, 2018 13:57
-
-
Save craigderington/b9532c7acfc54237275d41bf09b86f3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # items/forms.py | |
| from django import forms | |
| from .models import ItemLocation | |
| # define your models forms here | |
| class ItemLocationAdminForm(forms.ModelForm): | |
| qty_on_hand = forms.IntegerField() | |
| qty_on_order = forms.IntegerField() | |
| qty_in_transit = forms.IntegerField() | |
| class Meta: | |
| model = ItemLocation | |
| fields = ['qty_on_hand', 'qty_on_order', 'qty_in_transit'] | |
| def save(self, commit=True): | |
| qty_on_hand = self.cleaned_data['qty_on_hand'] | |
| qty_on_order = self.cleaned_data['qty_on_order'] | |
| qty_in_transit = self.cleaned_data['qty_in_transit'] | |
| instance = super(ItemLocationAdminForm, self).save(commit=False) | |
| instance.qty_on_hand = qty_on_hand | |
| instance.qty_on_order = qty_on_order | |
| instance.qty_in_transit = qty_in_transit | |
| if commit: | |
| instance.save() | |
| return instance |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment