Django documentation

40. Empty model tests

This example is for Django's SVN release, which can be significantly different from previous releases. Get old examples here: 0.96, 0.95.

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()