Hi Andrew,
Do you mean my model in my App?
If so I am posting it below.
Basically, as far as I know its a python 2.5 in the buildout that is used (2.5.2 to be exact)
Whats perplexing is that when I copied the model from the django-regions app into my own app the startmigrations --initial worked, however when I tried to do it on the django-regions app it failed with the Syntax error.
As you will see below, my model is complex.... However with the Country Model class copied into my models.py in my app, south works well, but trying to do the import of the model across apps it fails.
You surely know the innards better than i, however my gut feeling is that something in the django-regions app model fails, thats why the Country model works directly in my Application, but not in its own Application.
Please let me know if I can do any more, South is Django's missing piece of the Puzzle, thanks for all of your help
Regards
Mark
##################################
models.py in my application
##################################
from django.db import models
from model import ExpanderField
from django.contrib.auth.models import User
class CommonFields:
create_date = models.DateTimeField()
created_by = models.ForeignKey(User, related_name = 'created_by_set')
last_modified_by = models.ForeignKey(User, related_name = 'last_modified_by_set')
active = models.BooleanField(default=True)
class Merchant(CommonFields, models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=100)
country = models.ForeignKey(Country)
affiliate = models.ForeignKey(Affiliate)
common = ExpanderField(CommonFields)
def __unicode__(self):
return unicode("%s_%s"%(self.country.iso3,
self.name))
###################################
model.py in my utils for the ExpanderField
##################################
mport types
from copy import deepcopy
from django.db import models
class ExpanderField(object):
"""
This type of field can be used to include some common fields and methods in models.
It take a class with those common things as parameter in the constructor and will
add all fields in that class to models classes in which a field of
this class type is declared. If the class containing common fields
have fields of type: ForeignKey and ManyToManyField, then the related_name attribute
of those fields will be renamed to a value of the form: model_name_original_value .
Ej: if related_name = child_set and model name is MenuItem, it will be renamed to
MenuItem_child_set. To add methods of the common class you must inherit from it.
An importan thing to note here is that you must inherit first from the common class,
order matters.
Use case:
class ContentManager(models.Manager):
pass
class CommonFields:
pub_date = models.DateTimeField()
created_by = models.ForeignKey(User, related_name = 'created_by_set')
last_modified_by = models.ForeignKey(User, related_name = 'last_modified_by_set')
objects = ContentManager()
def save(self):
#do something
pass
class NewsItem(CommonFields, models.Model):
title = models.CharField(maxlength = 100)
body = models.CharField(maxlength = 200)
common = ExpanderField(CommonFields)
this will create a class of this form:
class NewsItem(models.Model):
title = models.CharField(maxlength = 100)
body = models.CharField(maxlength = 200)
pub_date = models.DateTimeField()
created_by = models.ForeignKey(User, related_name = 'created_by_set')
last_modified_by = models.ForeignKey(User, related_name = 'last_modified_by_set')
objects = ContentManager()
"""
def __init__(self, field_container_class):
self.field_container_class = field_container_class
def contribute_to_class(self, cls, name):
attr_list = [attr for attr in dir(self.field_container_class)
if attr not in ('__doc__', '__module__', '__class__', '__dict__')]
container = self.field_container_class
for attr in attr_list:
clone = None
attr_value = getattr(container, attr)
if type(attr_value) != types.MethodType:
clone = deepcopy(attr_value)
if (isinstance(clone, models.ForeignKey) or
isinstance(clone, models.ManyToManyField)) and \
clone.rel.related_name is not None:
clone.rel.related_name = cls.__name__ + '_' + clone.rel.related_name
if clone is not None:
cls.add_to_class(attr, clone)
##################################
Mark Ellul
Blog:
http://blog.catalystic.comLink Blog:
http://www.google.com/reader/public/atom/user/13607417594960986784/state/com.google/broadcast