Source

HackersEdge / he_one / managers.py

from django.db import models
import random

def generate_ip(network):
    return "%s.%s" % (network, random.randint(2,254))

class HostManager(models.Manager):
    def create_host(self, owner, network='192.168.0'):
        host = self.model(ip=generate_ip(network), owner=owner, is_router=False, is_booted=False, supports_mail=False)
        host.save()
        return host