How to use django-scheduler app in existing app

99封情书 提交于 2019-12-12 11:05:54

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/27239783/how-to-use-django-scheduler-app-in-existing-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!