Django documentation

39. Empty model tests

This example describes Django version 0.96. For the current example, go here.

These test that things behave sensibly for the rare corner-case of a model with no fields.

Model source code

from django.db import models

class Empty(models.Model):
    pass

Sample API usage

This sample code assumes the above model has been saved in a file mysite/models.py.

>>> from mysite.models import Empty

>>> m = Empty()
>>> m.id
>>> m.save()
>>> m2 = Empty()
>>> m2.save()
>>> len(Empty.objects.all())
2
>>> m.id is not None
True
>>> existing = Empty(m.id)
>>> existing.save()