如何在现有的应用程序中使用django

如何在现有的应用程序中使用django

本文介绍了如何在现有的应用程序中使用django-scheduler应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找django应用程序来处理Task Calendar事件,django-schedule示例项目提供了一个示例项目,但是我不知道如何将我的Task类(title& startTime)与事件类django schedule 。文档没有明确说明如何做到这一点如果可以在这里提供一些指针或步骤来使用现有的应用程序使用django-schedule应用程序,将会真的很好评。



这里的解决方案,但我无法做出很多的。我正在寻找一些关于如何将django-scheduler挂钩到我自己的模型的教程

解决方案

在互联网上发现这个好的对话,并作为参考,将解释如下逻辑:


  1. 假设你的任务类有startDateTime& endDateTime&标题

  2. 来自schedule.models import Event,EventRelation,Calendar(来自Schedule应用程序)

  3. 覆盖Task对象的保存方法以创建新事件如下所示,修改了上述链接中提供的代码,使其更清晰。

  4. 代码查找现有的日历,并通过关系将事件附加到与任务对象相关联的

  5. 尝试下面的代码来扩展源代码提供的Project-Sample应用程序,并且工作正常

      def save(self,force_insert = False,force_update = False):
    new_task = False
    如果不是self.id:
    new_task = True
    super(Task ,self).save(force_insert,force_update)
    end = self.startDateTime + timedelta(minutes = 24 * 60)
    title =这是测试任务
    如果new_task:
    event = Event(start = self.startDateTime,end = end,title = title,
    description = self.description)
    event.save()
    rel = EventRelation.objects.create_relation(event,self)
    rel.save()
    try:
    cal = Calendar.objects.get(pk = 1)
    除了Calendar.DoesNotExist:
    cal = Calendar(name =Community Calendar)
    cal.save()
    cal.events.add(event)
    else:
    event = Event.objects.get_for_object(self)[0]
    event.start = self.startDateTime
    event.end = end
    event.title = title
    事件。 description = self.description
    event.save()


仍然需要搜索在当前给出文本框的日历事件上扩展Click功能,如何使用超级链接进行自定义仍有待观察,但上面的代码解答问题和部分问题


I am looking for django apps to handle Task Calendar kind of event and django-schedule example project provides a sample project but I dont know how to map the my Task class (title & startTime) with the event class of django schedule. Documentation doesn't make it clear how can I do that? Will really apprciate if some pointers or steps can be provided here to use django-schedule app with an existing app

The solution here Using the Django scheduler app with your own models is present but I am not able to make much out of it. I am looking for some tutorial on how to hook django-scheduler to my own model

解决方案

Found this good conversation on internet https://groups.google.com/forum/#!topic/pinax-users/9NoRWjMdiyM and with as reference will explain the logic as below:

  1. Assume your task class to be having startDateTime & endDateTime & Title
  2. from schedule.models import Event, EventRelation, Calendar ( Coming from Schedule app)
  3. Override the save method of Task object to create new event as below , modified the code provided in the link above to make it clearer
  4. The code looks for a existing Calendar and attaches the event to it which is linked to the Task object via relationship
  5. Tried the code below to extend the Project-Sample app provided with the source and it worked fine

    def save(self, force_insert=False, force_update=False):
        new_task = False
        if not self.id:
            new_task = True
        super(Task, self).save(force_insert, force_update)
        end = self.startDateTime + timedelta(minutes=24*60)
        title = "This is test Task"
        if new_task:
            event = Event(start=self.startDateTime, end=end,title=title,
                      description=self.description)
            event.save()
            rel = EventRelation.objects.create_relation(event, self)
            rel.save()
            try:
                cal = Calendar.objects.get(pk=1)
            except Calendar.DoesNotExist:
                cal = Calendar(name="Community Calendar")
                cal.save()
            cal.events.add(event)
        else:
            event = Event.objects.get_for_object(self)[0]
            event.start = self.startDateTime
            event.end = end
            event.title = title
            event.description = self.description
            event.save()
    

Still have to search for extending the Click functionality on the Calendar event which currently gives a text box , how to customize that with a hyper link remains to be seen but the code above answers the question and part of the problem

这篇关于如何在现有的应用程序中使用django-scheduler应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 04:02