Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use django-scheduler app in existing app

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

like image 341
thedotnetdeveloper Avatar asked Dec 02 '14 00:12

thedotnetdeveloper


1 Answers

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

like image 174
thedotnetdeveloper Avatar answered Nov 06 '22 00:11

thedotnetdeveloper