Wednesday 15 July 2015

python - Django model inheritance overriding a variable used in field attribute -


I am trying to override some default values ​​in a inherited Django model. I need a model to have a group of different image sizes and 90% of the required areas are the same.

I have tried to use a base model to make and the child was going to add any additional fields required.

The problem I have is that the images are just using the "default" values ​​that I have determined and are not overwritten in the child model. ? What am I trying to accomplish possible

thanks

  class ImageLink (models.model): #default image size SIZED_WIDTH = 500 SIZED_HEIGHT = 400 THUMB_WIDTH = 50 THUMB_HEIGHT = 50 # Name = models of the name of the name * Model.CharField (MAX_LENGTH = 15) link image_original = models.ImageField (upload_to = "imageLink / images /% Y /% M /% d") image_sized = ImageSpecField (used for source Done #images = 'image_original', processor = [resizeToFill (SIZED_WIDTH, SIZED_HEIGHT)], format = 'JPEG', option = {'quality': 60}) image_thumb = ImageSpecField (source = 'image_original', processor = [ResizeToFill ( THUMB_WIDTH, THUMB_HEIGHT)], format = 'JPEG', and Class = {'Quality': 60}) Square Meta: Abstract = True # Model for all Poster Link Class PosterLink (ImageLink): #image Size SIZED_WIDTH = 200 SIZED_HEIGHT = 263 THUMB_WIDTH = 50 THUMB_HEIGHT = 66   

Assessment is when the class is defined. So when the subclass has been defined at the point, the area constructors have already been called and those values ​​have been called.

In addition, Django ORM is off. ImageKit fields are not the regular model fields, but since Django does not support this feature, it does not support some IK. (I am an escort.)

So you are going to live with some repetition or engross in the world of metaclasses. Alternatively, you can.

No comments:

Post a Comment