My problem is I create a model object and then save it. The data I put
in the model, which is not added. Instead an update of all similar
part numbers with the date occurs. I know about the override that
forces an insert. Is that what I should do?
Here is a sample of the data:
part_num,"ept_type","inv_id","load_date"
VWP-1602-201,43,80556338,"2011-02-15"
I'm
Here is the web template:
{% extends "base.html" %}
{% block content %}
<h2>Load Single Inventory Unit </h2>
{% if errors %}
{% for error in errors %}
{{ error }}
{% endfor %}
<br></br>
{% endif %}
<form action="." method="post"> {% csrf_token %}
Inventory Part Number:
<input type="text" name="part_num" size="12">
<br></br>
Inventory Type:
<input type="text" name="ept_type" size="2">
<br></br>
Inventory Serial Number (ID): <input type="text" name="inv_id"
size="8">
<br></br>
<input type="submit" value="Load Inventory Unit">
</form>
<a href="/">AMR Application Main Page</a>
{% endblock content %}
Here is the view subroutine to handle the request from the web page
(partial listing):
from amr.inventory_add.models import EptInv
from funcs import *
from util_lib import *
from util_class_lib import *
def load_inv(request):
errors = []
if request.method == 'POST':
if not request.POST.get('part_num', ''):
errors.append('Please enter a valid inventory part
number.')
else:
if not request.POST.get('ept_type', ''):
errors.append('Please enter a valid inventory type.')
else:
requested_serial_number =
request.POST.get('inv_id', '')
try:
temp_ept_id =
EptInv.objects.get(inv_id=requested_serial_number)
errors.append('Endpoint is present in
inventory.')
except ObjectDoesNotExist:
# element was not found - it is OK to add to
database.
gd = createGlobalData(getMySQLDateTime())
load_date = gd.getMySQLDate()
inv_obj = \
EptInv(part_num=request.POST.get('part_num'), \
ept_type=request.POST.get('ept_type'), \
inv_id=request.POST.get('inv_id'), \
load_date=load_date)
inv_obj.save()
Here is the model:
from django.db import models
class EptInv(models.Model):
part_num = models.CharField(max_length=60, blank=True)
ept_type = models.IntegerField(primary_key=True)
inv_id = models.IntegerField(primary_key=True)
load_date = models.DateField(null=True, blank=True)
class Meta:
db_table = u'ept_inv'
def __unicode__(self):
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.