Hi,

I'm trying to have a model inherit from another which has a custom
field:

import uuid
from django.db import models
from django.db.models.fields import CharField

class UuidField(CharField):        # <------------- The custom field
    def __init__(self, verbose_name=None, name=None, auto=False,
**kwargs):
        self.auto = auto
        kwargs['max_length'] = 36
        kwargs['unique'] = True
        if auto:
            kwargs['editable'] = False
            kwargs['blank'] = True
        super(UuidField, self).__init__(verbose_name, name, **kwargs)

    def pre_save(self, model_instance, add):
        value = super(UuidField, self).pre_save(model_instance, add)
        if (not value) and self.auto:
            # Assign a new value for this attribute if required.
            value = str(uuid.uuid1())
            setattr(model_instance, self.attname, value)
        return value

    def get_internal_type(self):
        return "UuidField"


Then, I do:

class AbstractClass(models.Model):
    uuid = UuidField(auto=True)
    name = models.CharField(max_length=80, blank=True)
    class Meta:
        abstract = True


class MyClass(AbstractClass):
    title = models.CharField(max_length=80, blank=True)


The problem is that when I run syncdb, the table 'myclass' only
contains the attributes 'name' and 'title', not 'uuid'.

What am I missing. Do I need to alter the UUIField class to make it
compatible with model inheritance?

Thanks a lot!

Julien
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to