My goal for today was to:

  1. Start the new kidsintown project, based on the django tutorial (mysite). Namely to turn all the poll models and views into events.
  2. Find a package that will help me with recurring events


Moving from mysite to kidsintown

  • It took me a lot of time to transition from the poll app to the events. The main issue was around urls and naming of views (that will be a reccuring theme…)
  • This didn’t take long to figure out, but I django yelled at me that I need to add the events app to the INSTALLED_APPS in my setting.py. But I didn’t have to do it with the django tutorial project… I still don’t understand what’s the different between the two projects.

Implementing django-recurrence

  • Implemented the django-reccuring package. I had an issue with getting it to work with my simple Event model, because I kept getting errors when trying to make a migration. Here’s how my model was looking like, according to the documentation:
from recurrence.fields import RecurrenceField

class Course(models.Model):
    title = models.CharField(max_length=200)
    recurrences = RecurrenceField()

I kept getting an error saying that I try to create a non-nullable field (recurrences) with a null value. After looking for code examples in github, I found one that worked:

class Event(models.Model):

    event_name = models.CharField(max_length=200)
    event_time = models.DateField()
    recurrence = RecurrenceField(blank=True, null=True)

    def __str__(self):
        return self.event_name
  • Documentation for packages in general, and that one in particular, isn’t good. There is now step-by-step tutorials, and you should figure out how the fragments of code integrating into your project. I found that looking for code examples in gitgub was helpful.
  • I had hard time implementing the form for creating recurrance in my templates. For example, in the documentation to the package, it is said that you should create a form like that:
from django import forms
from .models import Course

class EventForm(forms.ModelForm):
   class Meta:
      model = Event
      fields = ('event_name', 'recurrences',)

That didn’t work, and returned an error. After more github searches, I found that decleration that worked:

from django import forms
from .models import Event

class EventForm(forms.ModelForm):

    class Meta:
        model = Event
        exclude = []

Again, the documentation just show limited code examples, and I was left to figure some new concepts, such as forms. Fortunatly I found this great tutorial about creating forms a to z.

  • While the above tutorial was great, I still had issues – the redirect from the event creation to an event detail page after creation didn’t work. After many trails and errors, I found that the way I need to call a view accross the project is not only using it name, but also the app name, in the form of :.
  • Now to be honest, there is a section in the django tutorial that speaks into that previous point…