本文整理汇总了Python中models.Item.save方法的典型用法代码示例。如果您正苦于以下问题:Python Item.save方法的具体用法?Python Item.save怎么用?Python Item.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: item_form
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def item_form(request, id=None):
if id:
item = get_object_or_404(Item, id=id, company=request.company)
scenario = 'Update'
else:
item = Item(purchase_account=Account.objects.get(name='Purchase', company=request.company),
sales_account=Account.objects.get(name='Sales', company=request.company),
purchase_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company),
sales_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company))
scenario = 'Create'
if request.POST:
form = ItemForm(data=request.POST, instance=item, company=request.company)
if form.is_valid():
item = form.save(commit=False)
item.company = request.company
item.save()
if request.is_ajax():
return render(request, 'callback.html', {'obj': ItemSerializer(item).data})
return redirect('/inventory/items/')
else:
form = ItemForm(instance=item, company=request.company)
if request.is_ajax():
base_template = 'modal.html'
else:
base_template = 'dashboard.html'
return render(request, 'item_form.html', {
'scenario': scenario,
'form': form,
'base_template': base_template,
})
示例2: test_update
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def test_update(self):
order = Order(name="Dummy Order")
order.save()
for i in range(2):
item = Item(name="Item %i" % i, sku=str(i) * 13, price=D("9.99"), order=order, status=0)
item.save()
tag = Tag(name="Test", content_object=order)
tag.save()
res = self.client.get("/inlines/1/")
self.assertEqual(res.status_code, 200)
order = Order.objects.get(id=1)
self.assertEquals(2, order.item_set.count())
self.assertEquals("Item 0", order.item_set.all()[0].name)
data = {
"name": u"Dummy Order",
"item_set-TOTAL_FORMS": u"4",
"item_set-INITIAL_FORMS": u"2",
"item_set-MAX_NUM_FORMS": u"",
"item_set-0-name": "Bubble Bath",
"item_set-0-sku": "1234567890123",
"item_set-0-price": D("9.99"),
"item_set-0-status": 0,
"item_set-0-order": 1,
"item_set-0-id": 1,
"item_set-1-name": "Bubble Bath",
"item_set-1-sku": "1234567890123",
"item_set-1-price": D("9.99"),
"item_set-1-status": 0,
"item_set-1-order": 1,
"item_set-1-id": 2,
"item_set-2-name": "Bubble Bath",
"item_set-2-sku": "1234567890123",
"item_set-2-price": D("9.99"),
"item_set-2-status": 0,
"item_set-2-order": 1,
"item_set-3-DELETE": True,
"tests-tag-content_type-object_id-TOTAL_FORMS": 3,
"tests-tag-content_type-object_id-INITIAL_FORMS": 1,
"tests-tag-content_type-object_id-MAX_NUM_FORMS": u"",
"tests-tag-content_type-object_id-0-name": u"Test",
"tests-tag-content_type-object_id-0-id": 1,
"tests-tag-content_type-object_id-0-DELETE": True,
"tests-tag-content_type-object_id-1-name": u"Test 2",
"tests-tag-content_type-object_id-2-name": u"Test 3",
}
res = self.client.post("/inlines/1/", data, follow=True)
self.assertEqual(res.status_code, 200)
order = Order.objects.get(id=1)
self.assertEquals(3, order.item_set.count())
self.assertEquals(2, Tag.objects.count())
self.assertEquals("Bubble Bath", order.item_set.all()[0].name)
示例3: post_item
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def post_item(request):
if request.method == 'POST':
form = ItemForm(request.POST, request.FILES)
if form.is_valid():
m_tags = form.cleaned_data['item_tags']
m = Item(
name=form.cleaned_data['item_name'],
# type=form.cleaned_data['item_type'],
# item_image=request.FILES['item_image'],
image_first = form.cleaned_data['image_first'],
image_second= form.cleaned_data['image_second'],
image_third= form.cleaned_data['image_third'],
looking_for = True if 'True' == form.cleaned_data['item_sellOrLookFor'] else False,
category = form.cleaned_data['item_category'],
#price=form.cleaned_data['item_price'],
negotiable=form.cleaned_data['item_negotiable'],
owner=request.user,
description=form.cleaned_data['item_description']
)
m.save()
print "item has been saved with item_id "+str(m.pk)
print m_tags
m.tags.add(*m_tags)
# return my_items(request)
return HttpResponseRedirect('/')
else:
form = ItemForm()
return render_to_response('post_item.html', {'form': form, 'user': request.user}, context_instance=RequestContext(request))
示例4: test_saving_and_retrieving_items
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def test_saving_and_retrieving_items(self):
list_ = List()
list_.save()
first_item = Item()
first_item.text = 'The first (ever) list item'
first_item.list = list_
first_item.save()
second_item = Item()
second_item.text = 'Item the second'
second_item.list = list_
second_item.save()
saved_list = List.objects.first()
self.assertEqual(saved_list, list_)
saved_items = Item.objects.all()
self.assertEqual(saved_items.count(), 2)
first_saved_item = saved_items[0]
second_saved_item = saved_items[1]
self.assertEqual(first_saved_item.text, 'The first (ever) list item')
self.assertEqual(first_saved_item.list, list_)
self.assertEqual(second_saved_item.text, 'Item the second')
self.assertEqual(second_saved_item.list, list_)
示例5: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def post(self):
form = AddItemForm()
item = Item()
if form.validate_on_submit():
ar_title = Titles()
fr_title = Titles()
en_title = Titles()
ar_title.title = form.ar_title.data.strip()
ar_title.lang = 'ar'
fr_title.title = form.fr_title.data.strip()
fr_title.lang = 'fr'
en_title.title = form.en_title.data.strip()
en_title.lang = 'en'
item.titles.append(ar_title)
item.titles.append(fr_title)
item.titles.append(en_title)
item.description = form.description.data
item.submitter = User.objects.get(id=current_user.id)
else:
flash('upload unsuccessful', 'error')
return render_template('items/add_item.html', form=form)
uploaded_files = request.files.getlist("files")
thumbnail = request.files['thumbnail']
thumbnail_name = secure_filename(thumbnail.filename)
if thumbnail and allowed_thumbnails(thumbnail_name):
ext = thumbnail.mimetype.split('/')[-1]
# use the 'thumbnail' name for all thumbnails
filename = '.'.join(["thumbnail", ext])
item.thumbnail.put(thumbnail.stream,
content_type=thumbnail.mimetype,
filename=filename)
for file in uploaded_files:
# Make the filename safe, remove unsupported chars
filename = secure_filename(file.filename)
# Check if the file is one of the allowed types/extensions
if file and allowed_file(filename):
# put the file in the ListField.
# see https://gist.github.com/tfausak/1299339
file_ = GridFSProxy()
file_.put(file.stream,
content_type=file.mimetype,
filename=filename)
item.files.append(file_)
# Save the thing
item.save()
flash('upload successful')
return render_template('items/add_item.html', form=form)
示例6: test_update
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def test_update(self):
order = Order(name='Dummy Order')
order.save()
for i in range(2):
item = Item(name='Item %i' % i, sku=str(i) * 13, price=D('9.99'), order=order, status=0)
item.save()
tag = Tag(name='Test', content_object=order)
tag.save()
res = self.client.get('/inlines/1/')
self.assertEqual(res.status_code, 200)
order = Order.objects.get(id=1)
self.assertEquals(2, order.item_set.count())
self.assertEquals('Item 0', order.item_set.all()[0].name)
data = {
'name': u'Dummy Order',
'item_set-TOTAL_FORMS': u'4',
'item_set-INITIAL_FORMS': u'2',
'item_set-MAX_NUM_FORMS': u'',
'item_set-0-name': 'Bubble Bath',
'item_set-0-sku': '1234567890123',
'item_set-0-price': D('9.99'),
'item_set-0-status': 0,
'item_set-0-order': 1,
'item_set-0-id': 1,
'item_set-1-name': 'Bubble Bath',
'item_set-1-sku': '1234567890123',
'item_set-1-price': D('9.99'),
'item_set-1-status': 0,
'item_set-1-order': 1,
'item_set-1-id': 2,
'item_set-2-name': 'Bubble Bath',
'item_set-2-sku': '1234567890123',
'item_set-2-price': D('9.99'),
'item_set-2-status': 0,
'item_set-2-order': 1,
'item_set-3-DELETE': True,
'tests-tag-content_type-object_id-TOTAL_FORMS': 3,
'tests-tag-content_type-object_id-INITIAL_FORMS': 1,
'tests-tag-content_type-object_id-MAX_NUM_FORMS': u'',
'tests-tag-content_type-object_id-0-name': u'Test',
'tests-tag-content_type-object_id-0-id': 1,
'tests-tag-content_type-object_id-0-DELETE': True,
'tests-tag-content_type-object_id-1-name': u'Test 2',
'tests-tag-content_type-object_id-2-name': u'Test 3',
}
res = self.client.post('/inlines/1/', data, follow=True)
self.assertEqual(res.status_code, 200)
order = Order.objects.get(id=1)
self.assertEquals(3, order.item_set.count())
self.assertEquals(2, Tag.objects.count())
self.assertEquals('Bubble Bath', order.item_set.all()[0].name)
示例7: create_item
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def create_item(request):
"""
@param request:
@param id:
@return: JSON for account for added Inventory Item
"""
item = Item(purchase_account=Account.objects.get(name='Purchase', company=request.company),
sales_account=Account.objects.get(name='Sales', company=request.company),
purchase_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company),
sales_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company))
scenario = 'Create'
for query in request.GET:
setattr(item, query, request.GET[query])
if request.POST:
form = ItemForm(data=request.POST, instance=item, company=request.company)
if form.is_valid():
item = form.save(commit=False)
item.company = request.company
item.save()
if request.is_ajax():
return render(request, 'callback.html', {'obj': InventoryAccountSerializer(item.account).data})
return redirect('/inventory/items/')
else:
form = ItemForm(instance=item, company=request.company)
form.hide_field(request)
if request.is_ajax():
base_template = 'modal.html'
else:
base_template = 'dashboard.html'
return render(request, 'item_form.html', {
'scenario': scenario,
'form': form,
'base_template': base_template,
})
示例8: test_format_item_to_json
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def test_format_item_to_json(self):
item = Item(1, "test name", "Medium", "This is a test description")
item.save()
results = item.to_json()
expected_results = dict(id=1, user_id=1, name="test name", priority="Medium",
description="This is a test description")
self.assertEqual(expected_results, results)
示例9: updateLocalDB
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def updateLocalDB(request):
cursor = connections['cineca'].cursor() # Cursor connessione Cineca
cursorLocal = connections['default'].cursor() # Cursor DB locale
# Seleziona tutti i dati necessari dal DB remoto
cursor.execute(
"SELECT \
INV.ID_INVENTARIO_BENI,\
INV.DS_BENE,\
MOV.DT_REGISTRAZIONE_BUONO,\
INV.VALORE_CONVENZIONALE,\
SPA.DS_SPAZIO,\
INV.DT_INI_AMMORTAMENTO,\
INV.VALORE_CONVENZIONALE - (LEAST((extract(year from sysdate) - EXTRACT(year FROM INV.DT_INI_AMMORTAMENTO)),AMM.NUM_ANNUALITA) * (INV.VALORE_CONVENZIONALE / AMM.NUM_ANNUALITA)) AS VALORE_RESIDUO\
FROM\
(((V_IE_CO_MOVIMENTI_BENE MOV RIGHT JOIN V_IE_CO_INVENTARIO_BENI INV\
ON MOV.ID_INVENTARIO_BENI = INV.ID_INVENTARIO_BENI) LEFT JOIN\
V_IE_AC_SPAZI SPA ON INV.CD_UBICAZIONE = SPA.CD_SPAZIO) INNER JOIN\
V_IE_CO_AS_TIP_AMM_CAT_GRP_INV AMM on INV.CD_CATEG_GRUPPO = AMM.CD_CATEG_GRUPPO )\
WHERE\
(AMM.ESERCIZIO - EXTRACT(year FROM INV.DT_INI_AMMORTAMENTO)) = 0\
ORDER BY\
MOV.ID_INVENTARIO_BENI DESC"
)
rows = rows_to_dict_list(cursor)
# Scorre tutti i dati riga per riga
for row in rows:
# Per ogni riga vede se l'oggetto esiste gia' nel database
try:
#print "obj ",row['ID_INVENTARIO_BENI'],"val res: ",row['VALORE_RESIDUO']
item = Item.objects.get(item_id=row['ID_INVENTARIO_BENI'])
# Se l'oggetto esiste i dati vengono aggiornati
item.item_id = row['ID_INVENTARIO_BENI']
item.description = row['DS_BENE'] if row['DS_BENE'] else ''
item.purchase_date = row['DT_REGISTRAZIONE_BUONO'] if row['DT_REGISTRAZIONE_BUONO'] is not None else '0001-01-01 00:00'
item.price = row['VALORE_CONVENZIONALE'] if row['VALORE_CONVENZIONALE'] else -1
item.location = row['DS_SPAZIO'] if row['DS_SPAZIO'] is not None else ''
item.depreciation_starting_date = row['DT_INI_AMMORTAMENTO'] if row['DT_INI_AMMORTAMENTO'] else '0001-01-01 00:00'
item.residual_value = row['VALORE_RESIDUO'] if row['VALORE_RESIDUO'] is not None else -1
# item = Item(None,item_id,description,purchase_date,price,location,depreciation_starting_date)
item.save()
except Item.DoesNotExist:
# Se non esiste viene creato un nuovo oggetto
item_id = row['ID_INVENTARIO_BENI']
description = row['DS_BENE'] if row['DS_BENE'] else ''
purchase_date = row['DT_REGISTRAZIONE_BUONO'] if row['DT_REGISTRAZIONE_BUONO'] is not None else '0001-01-01 00:00'
price = row['VALORE_CONVENZIONALE'] if row['VALORE_CONVENZIONALE'] else -1
location = row['DS_SPAZIO'] if row['DS_SPAZIO'] is not None else ''
depreciation_starting_date = row['DT_INI_AMMORTAMENTO'] if row['DT_INI_AMMORTAMENTO'] else '0001-01-01 00:00'
residual_value = row['VALORE_RESIDUO'] if row['VALORE_RESIDUO'] is not None else -1
item = Item(None,item_id,description,purchase_date,price,location,depreciation_starting_date,residual_value)
item.save()
return redirect ('showLocalDB')
示例10: count_increase
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def count_increase(self, book_id, **kwargs):
try:
item = self.session.query(Item).filter(Item.book_id == book_id).one()
except:
item = Item()
item.book_id = book_id
item.count_guest += kwargs.get('count_guest', 0)
item.count_visit += kwargs.get('count_visit', 0)
item.count_download += kwargs.get('count_download', 0)
item.save()
示例11: test_context
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def test_context(self):
order = Order(name="Dummy Order")
order.save()
for i in range(10):
item = Item(name="Item %i" % i, sku=str(i) * 13, price=D("9.99"), order=order, status=0)
item.save()
res = self.client.get("/modelformset/simple/")
self.assertTrue("object_list" in res.context)
self.assertEquals(len(res.context["object_list"]), 10)
示例12: setUp
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def setUp(self):
super(ItemApiTest, self).setUp()
# Create a user.
self.username = 'test_user'
self.password = 'test_pass'
self.user = User.objects.create_user(self.username, '[email protected]', self.password)
# Create another user
self.username2 = 'test_user2'
self.password2 = 'test_pass2'
self.user2 = User.objects.create_user(self.username2, '[email protected]', self.password2)
item = Item()
item.name = "Test Item #1"
item.user = self.user
item.notes = "testing..."
item.save()
self.item = item
# Build a URI for the item
self.detail_uri = '/api/v1/todo/{0}/'.format(self.item.pk)
# ...as well as a URI to list all items
self.list_uri = '/api/v1/todo/'
# ...and URIs for each user
self.user_uri = '/api/v1/user/{0}/'.format(self.user.pk)
self.user2_uri = '/api/v1/user/{0}/'.format(self.user2.pk)
# The data we'll send on POST requests.
self.post_data = {
'user': self.user_uri,
'name': 'Test Item #2'
}
self.post_data2 = {
'user': self.user2_uri,
'name': 'Test Item #3'
}
# Expected test item JSON from server
self.test_item_json = {
'name': 'Test Item #1',
'created': str(self.item.created),
'notes': 'testing...',
'due': None,
'priority': 0,
'done': False,
'user': self.user_uri,
'id': str(self.item.pk),
'resource_uri': self.detail_uri
}
示例13: add_item
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def add_item(request):
if request.POST:
item = Item()
item.name = request.POST['item_name']
item.description = request.POST['description']
item.seller = request.user
item.save()
# url = reverse('add_auction', kwargs={ 'item_id': item.id })
return HttpResponseRedirect(reverse('auction:add_auction', args=(item.id,)))
return render(request, 'add_item.html', {})
示例14: test_create
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def test_create(self):
order = Order(name='Dummy Order')
order.save()
for i in range(10):
item = Item(name='Item %i' % i,sku=str(i)*13,price=D('9.99'),order=order, status=0)
item.save()
res = self.client.get('/inlineformset/1/')
self.assertEqual(res.status_code, 200)
self.assertTrue('formset' in res.context)
self.assertFalse('form' in res.context)
示例15: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import save [as 别名]
def post(self):
data = json.loads(request.data)
if 'name' not in data:
return make_response('The list item name is required', 400)
else:
name = data.get('name')
user_id = data.get('user_id')
description = data.get('description') if 'description' in data else None
priority = data.get('priority') if 'priority' in data else None
item = Item(user_id, name, priority, description)
item.save()
return make_response(jsonify(item.to_json()), 200)