Пример #1
0
 def save_model(self, request, obj, form, change):
     obj.creator_name = request.user.username
     obj.creator_id = request.user.id
     obj.disabled = "N"
     if not change:
         obj.archive_date = time.strftime("%Y年%m月", time.localtime())
     if obj.content.find("</p>") == -1:
         obj.short_content = obj.content
     else:
         obj.short_content = obj.content[: obj.content.find("</p>") + 4]
     obj.save()
     if not change:
         category = obj.category
         category.id_num = category.id_num + 1
         category.save()
         acount = Archive.objects.filter(
             creator_name=request.user.username, archive_date=obj.archive_date, disabled="N"
         ).count()
         if acount == 0:
             archive = Archive()
             archive.archive_date = obj.archive_date
             archive.archive_num = 1
             archive.creator_id = request.user.id
             archive.creator_name = request.user.username
             archive.disabled = "N"
         else:
             archive = Archive.objects.filter(
                 creator_name=request.user.username, archive_date=obj.archive_date, disabled="N"
             )[0]
             archive.archive_num = archive.archive_num + 1
         archive.save()