Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- models.py
- ------------
- UNIT_CHOICES = (
- ('dumb_terminal', 'Dumb Terminal'),
- ('computer', 'Computer'),
- )
- class Unit(models.Model):
- unittype = models.CharField( choices=UNIT_CHOICES)
- forms.py
- ------------
- class GenericForm(ModelForm):
- class Meta:
- model = Inventory_Unit
- class computerForm(ModelForm):
- class Meta:
- model = Inventory_Unit
- fields = ('make', 'model', 'serial', 'drive_number', 'asset_tag', 'asset_tag_2')
- views.py
- ------------
- @login_required
- def inventory_freight(request, p_id):
- shipment = get_object_or_404(Shipment, id=p_id)
- message = ""
- addform = ""
- selection = "No selection"
- query = request.GET.get('unit_select', '')
- if query:
- if hasattr(forms, query+'Form'):
- formClass = getattr(forms, query+'Form')
- else:
- formClass = forms.GenericForm
- selection = "You've selected " + query
- addform = formClass()
- if request.method == 'POST':
- addform = formClass(request.POST)
- if addform.is_valid():
- instance = addform.save(commit=False)
- instance.shipment = shipment
- instance.unittype = query
- instance.save()
- # Form is valid and the new unit has been saved.
- # so we'll return a new empty unit for the user to fill in.
- form = formClass()
- message = "Unit successfully saved."
- else:
- addform = formClass()
- message = "Add "+ query +" Unit"
- else:
- #results = []
- selection = "No unit type has been selected..."
- return render_to_response('inventory_shipment.html', {'units': shipment.inventory_unit_set.all(), 'selection': selection, 'shipment': shipment, 'addform': addform, 'UNIT_CHOICES': UNIT_CHOICES,})
- template
- ---------
- {% extends "base_site.html" %}
- {% block title %}Order: PCD{{ shipment.id }}<div style="float: right;"><a href="/shiptrack/ci/search/"><input type="button" value="Back to Orders"></a></div>
- {% endblock %}
- {% block content %}
- <b>Company Name:</b> {{ shipment.company }}
- <br />
- <br />
- <div style="float: left; width: 25%">
- {{ selection }}<br />
- <br />
- <form method="get">
- <select name='unit_select' size="15" onchange='this.form.submit()'>
- <option value = "EMPTY">Choose a unit type...</option>
- {% for c in UNIT_CHOICES %}
- <option value = "c[0]">c[1]</option>
- {% endfor %}
- </select>
- </form>
- </div>
- <div style="float: right; width: 73%">
- {% if addform %}
- <form method="post">
- {{ addform.as_p }}
- <input type="submit" onmouseover="Tip('Click here to add a unit to this order.')" onmouseout="UnTip()" value="Add Unit" name="Add Unit" />
- </form>
- {% endif %}
- </div>
- <br />
- <div style="clear: both;"> <br /></div>
- {% if units %}
- {% for s in units %}
- <tr class="{% cycle odd,even %}">
- <td><a href="">{{s.unittype}}</a></td>
- <td><a href="">{{s.make}}</a></td>
- <td><a href="">{{s.model}}</a></td>
- <td><a href="">{{s.serial}}</a></td>
- <td><a href="">{{s.asset_tag}}</a></td>
- </tr>
- {% endfor %}
- {% else %}
- <p>No units.</p>
- {% endif %}
- {% endblock %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement