def New_subject(request): User = get_user_model() # custom user user = request.user new_subject = Subject(title = request.POST['subject_title'], user = user) new_subject.save() topic = Topic(user = user, subject = new_subject, name = "Your first topic") topic.save() summary = Summary(user = user, subject = new_subject, topic = topic, content = "This is your very first Summary. In Lynx, Topics and Summaries are saved automatically, so you don't have to worry about that.") summary.save() return HttpResponseRedirect("/dashboard/")
def New_dynamic(request, slug): # create new DYNAMIC Topic and Summary 'in background' User = get_user_model() # custom user user = request.user subject = Subject.objects.get(user=request.user, slug=slug) if request.is_ajax(): topic = Topic(subject = subject, user = user, name = "New topic") topic.save() summary = Summary(subject = subject, user = user, topic = topic, content = "New summary") summary.save() topicCount = Topic.objects.filter(user = user, subject = subject).count() # date serialization topicDate = datetime.datetime.now() serialized_datetime = formats.date_format(topicDate, 'DATETIME_FORMAT') data = json.dumps({'dynamic_topic_id': topic.id, 'dynamic_summary_id': summary.id, "topicCount" : topicCount, "topicDate" : topicDate, "serialized_datetime" : serialized_datetime}, cls=DjangoJSONEncoder) else: return HttpResponseRedirect("/dashboard/") # not possible? return HttpResponse(data, mimetype='application/json')