本文整理汇总了Python中models.Record.date_added方法的典型用法代码示例。如果您正苦于以下问题:Python Record.date_added方法的具体用法?Python Record.date_added怎么用?Python Record.date_added使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Record
的用法示例。
在下文中一共展示了Record.date_added方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: acquisition
# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import date_added [as 别名]
#.........这里部分代码省略.........
record.publication_has_month = True
except ValueError:
record.date_of_publication = datetime.strptime(data['data']['publish_date'], '%m/%d/%Y').date()
record.publication_has_day = True
record.publication_has_month = True
if data['data'].has_key('identifiers'):
if data['data']['identifiers'].has_key('openlibrary'):
record.openlibrary_id = data['data']['identifiers']['openlibrary'][0]
if data['data']['identifiers'].has_key('goodreads'):
record.goodreads_id = data['data']['identifiers']['goodreads'][0]
if data['data']['identifiers'].has_key('librarything'):
record.librarything_id = data['data']['identifiers']['librarything'][0]
if data['data']['identifiers'].has_key('oclc'):
record.oclc_id = data['data']['identifiers']['oclc'][0]
if data['data']['identifiers'].has_key('lccn'):
record.lccn_id = data['data']['identifiers']['lccn'][0]
if data['data'].has_key('by_statement'):
record.by_statement = data['data'].get('by_statement')
if data['data'].has_key('notes'):
record.notes = data['data'].get('notes')
if data['data'].has_key('excerpts'):
record.excerpt = data['data'].get('excerpts')[0].get('text')
record.book = book
setting = LibrarySetting.get()
record.type = setting.default_type
if new_record:
record.date_added = datetime.today()
record.save()
if data['details']['details'].has_key('languages'):
record.languages.clear()
for lang in data['details']['details']['languages']:
lang_key = lang['key'].replace('/languages/', '')
try:
book_lang = Language.objects.get(code=lang_key)
except Language.DoesNotExist:
try:
book_lang = Language.objects.get(code=lang_key[:-1])
except Language.DoesNotExist:
raise Exception(
"Please add a language with code " + lang_key + " or " + lang_key[:-1] + " first!")
record.languages.add(book_lang)
if data['data'].has_key('publish_places'):
record.published_places.clear()
for place in data['data']['publish_places']:
try:
published_place = Place.objects.get(name=place['name'])
except Place.DoesNotExist:
published_place = Place(name=place['name'])
published_place.save()
record.published_places.add(published_place)
record.authors.clear()
if data['details']['details'].has_key('authors'):
for author in data['details']['details']['authors']:
author_key = author['key'].replace('/authors/', '')
try:
book_author = Author.objects.get(identifier=author_key)
示例2: save_acquisition
# 需要导入模块: from models import Record [as 别名]
# 或者: from models.Record import date_added [as 别名]
def save_acquisition(request):
if request.POST.get('book').isnumeric():
book = Book.objects.get(id=request.POST.get('book'))
new_book = False
else:
book = Book(title=request.POST.get('book'))
new_book = True
book.subtitle = request.POST.get('subtitle')
book.save()
if request.POST.get('isbn'):
isbn = request.POST.get('isbn')
if isbnpy.isValid(isbn):
if isbnpy.isI10(isbn):
isbn = isbnpy.convert(isbn)
try:
record = Record.objects.get(isbn13=isbn)
new_record = False
except Record.DoesNotExist:
record = Record(isbn13=isbn)
new_record = True
else:
if not new_book:
try:
record = Record.objects.get(book=book, edition=request.POST.get('book'))
new_record = False
except Record.DoesNotExist:
record = Record(book=book)
new_record = True
else:
record = Record(book=book)
new_record = True
record.book = book
record.format = request.POST.get('format')
if record.format != 'ebook':
if new_record:
record.quantity = request.POST.get('quantity')
else:
record.quantity += int(request.POST.get('quantity'))
record.excerpt = request.POST.get('excerpt')
record.edition = request.POST.get('edition')
record.notes = request.POST.get('notes')
record.ddc = request.POST.get('ddc')
record.lcc = request.POST.get('lcc')
record.pagination = request.POST.get('pagination')
record.format = request.POST.get('format')
record.type = request.POST.get('type')
if record.format != 'eBook':
record.quantity = request.POST.get('quantity')
record.publication_has_month = False
record.publication_has_day = False
if request.POST.get('year'):
dt = datetime(int(request.POST.get('year')), 1, 1)
if request.POST.get('month'):
record.publication_has_month = True
dt = dt.replace(month=int(request.POST.get('month')))
if request.POST.get('day'):
record.publication_has_day = True
dt = dt.replace(day=int(request.POST.get('day')))
record.date_of_publication = dt
else:
record.date_of_publication = None
if request.FILES.get('small_cover'):
record.small_cover = request.FILES.get('small_cover')
if request.FILES.get('medium_cover'):
record.medium_cover = request.FILES.get('medium_cover')
if request.FILES.get('large_cover'):
record.large_cover = request.FILES.get('large_cover')
if not record.date_added:
record.date_added = datetime.today()
record.save()
if request.FILES.get('ebook'):
ebooks = request.FILES.getlist('ebook')
for ebook in ebooks:
ebook_file = BookFile(record=record, file=ebook)
existing_files = record.ebooks(ebook_file.format)
for existing_file in existing_files:
existing_file.delete()
ebook_file.save()
book.subjects.clear()
for subject in request.POST.getlist('subjects'):
if subject.isnumeric():
book.subjects.add(Subject.objects.get(id=subject))
else:
new_subject = Subject(name=subject)
new_subject.save()
book.subjects.add(new_subject)
record.authors.clear()
for author in request.POST.getlist('authors'):
if author.isnumeric():
record.authors.add(Author.objects.get(id=author))
#.........这里部分代码省略.........