KVISH
KVISH

Reputation: 13178

South is not recognizing my model

I have the following class called UnixTimestampField:

from django.db import models
from datetime import datetime
from time import strftime

class UnixTimestampField(models.DateTimeField):
    op_params=''
    def __init__(self, null=False, blank=False, op_params='', **kwargs):
        super(UnixTimestampField, self).__init__(**kwargs)
        self.blank, self.isnull = blank, null
        self.null = True

    def db_type(self, connection):
        typ=['TIMESTAMP']
        # See above!
        if self.isnull:
            typ += ['NULL']
        if self.op_params != '':
            typ += [self.op_params]
        return ' '.join(typ)

    def to_python(self, value):
        return datetime.from_timestamp(value)

    def get_db_prep_value(self, value, connection, prepared=False):
        if value==None:
            return None
        return strftime('%Y%m%d%H%M%S',value.timetuple())

    def to_python(self, value):
        return value

from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^web\customfields\.unixtimestampfield\.UnixTimestampField"])

Every time I run the following command: python manage.py schemamigration web --initial, I keep getting:

! (this field has class web.customfields.unixtimestampfield.UnixTimestampField)

Is there something i'm missing? It doesn't seem to even recognize the field exists? I was reading the documentation at:

http://south.readthedocs.org/en/latest/customfields.html#extending-introspection

http://south.readthedocs.org/en/latest/tutorial/part4.html#keyword-arguments

[SOLUTION]

The error was a simple one.

The following line: ^web\customfields\.unixtimestampfield\.UnixTimestampField is incorrect.

It was changed to: ^web\.customfields\.unixtimestampfield\.UnixTimestampField

Upvotes: 1

Views: 170

Answers (1)

Goin
Goin

Reputation: 3964

This is tatty. But you can change the UnixTimestampField in your model to a DateTimeField. Execute this:

python manage.py schemamigration web --initial

And after you change another time the DateTimeField to UnixTimestampField

This must work.... but this is dirty solution

Althought it is possible that you have a error in your code, change this:

add_introspection_rules([], ["^web\customfields\.unixtimestampfield\.UnixTimestampField"])

for this:

add_introspection_rules([], ["^web\.customfields\.unixtimestampfield\.UnixTimestampField"])

Upvotes: 1

Related Questions