Modelling

Automatic created and modified timestamps

from django_extensions.db.models import TimeStampedModel
class MyModel(TimeStampedModel)

Tree-based models

mptt_model.get_ancestors()
mptt_model.get_descendants()

Get UML for models

django-admin.py graph_models app -o app.png

Introspection

  • Get all attributes

User._meta.fields()
  • Check attribute type

isinstance(field, models.ForeignKey)
  • Where is the foreign key pointing to?

field.rel.to
search_column = "name_" + lang
search_value = self.kwargs.get("category")
Category.objects.filter(**{ search_column: search_value })