Contributing to Pretix

Recently I had the chance to contribute to Pretix ( a Django-based event ticketing platform.

I submitted a couple of merge requests that were accepted: -

I will briefly detail some of the key learnings:

  1. Django models: Being absolutely new to Django, I had the opportunity to learn along the way about one of its key features, the Models. Models are objects that the ORM will store in the database, a quick intro here: It was quite surprising as well the ease of the development thanks to the automatic migrations in the database schema. More detailed info on Models here:

  2. all keyword in Python: In order to check whether a condition was True for all the elements of a list I simply iterated over them and checked for the condition:

    for i, op in enumerate(positions):
    if False in cancelable_products:
        cancelable = False

    However a much simpler solution making use of list comprehensions and the all() keyword in Python is possible:

    cancelable = all([op.item.allow_cancel for op in positions])
  3. Metaclasses in Python: Although I had read about Python Metaclasses in this excellent post (, Django Models are a really good practical example of their value and use. The Metaclasses are used in the Django Models to dynamically create classes.

  4. Difference between select_related and prefetch_related in Django: prefetch_related: does a separate lookup for each relationship, and does the ‘joining’ in Python. This allows it to prefetch many-to-many and many-to-one objects.
    select_related: limited to single-valued relationships - foreign key and one-to-one. Creates an SQL join including the fields of the related object in the SELECTstatement retrieving the related objects in the same (but more complex) database query.
    By using select_related instead of prefetch_related, one query to the DB is saved.  More info on Django QuerySet:

Head over to this post for more details on Metaclasses in Django:

comments powered by Disqus