I updated my model files in the module - thus, it is much easier to maintain the code, as it has grown a bit.
The funny thing is that it will not work for one of the classes that refers to another class that refers to the fist in it:
UPD: references to cyclicity confuse python, and it is for this reason that the problem is caused. This can be easily fixed if you only reference other models from the model definition. However, Picture does have methods that reference the paperType class and vice versa - how can this be eliminated?
Here's a class picture:
from django.db import models from django.utils import simplejson from picviewer.models import Collection, ImageSizeRatio, printSize class Picture(models.Model): name = models.TextField(null=False,blank=False,unique=False) collection = models.ForeignKey(Collection) popularity = models.IntegerField(default=0,unique=False) isPurchasable = models.BooleanField(default=False) allowBuyExclusive = models.BooleanField(default=False) basePrice = models.DecimalField(decimal_places=2,max_digits=8) imageSizeRatio = models.ForeignKey(ImageSizeRatio) imageThumbnail = models.FileField(upload_to='pictures') imagePreview = models.FileField(upload_to='pictures') imageSmall = models.FileField(upload_to='pictures') imageNormal = models.FileField(upload_to='pictures') imageLarge = models.FileField(upload_to='pictures') imageHuge = models.FileField(upload_to='pictures') allowedPrintSize = models.ManyToManyField(printSize)
Here is the printSize class that it refers to - you see that it calls the Picture functions to do some math around the images of the specified printSize:
from django.db import models from picviewer.models import paperType from picviewer.models import Picture class printSize (models.Model): name = models.CharField(null=False,blank=False,unique=True,max_length=60) width = models.IntegerField(null=False,blank=False) height = models.IntegerField(null=False,blank=False) allowedPaperType = models.ManyToManyField(paperType)
now this is what i get in a shell trying to import an image:
>>> from picviewer.models import Picture Traceback (most recent call last): File "<console>", line 1, in <module> File "D:\~Sasha\eclipse_workspace\zavalen\picviewer\models\Picture.py", line 4, in <module> from picviewer.models import Collection, ImageSizeRatio, printSize File "D:\~Sasha\eclipse_workspace\zavalen\picviewer\models\printSize.py", line 4, in <module> from picviewer.models import Picture ImportError: cannot import name Picture >>>
Can this be cured? :)