class Field(object):
def __init__(self, label=None, value=None, flag=None):
self.label = label
self.value = value
self.flag = flag
@property
def value(self):
return self.__value
@value.setter
def value(self, value):
self.__value = value
@property
def flag(self):
return self.__flag
@flag.setter
def flag(self, flag):
self.__flag = flag
def to_representation(self):
return {
'label': self.label,
'value': self.value,
'flag': self.flag
}
class Test(object):
field1 = Field('Поле №1')
field2 = Field('Поле №2')
field3 = Field('Поле №3')
class Meta:
fields = ('field1', 'field2', 'field3') # Здесь можно по быстрому исключать поля
def __init__(self, data):
self.field1.value = data
@property
def data(self):
results = []
for field in self.Meta.fields:
field = getattr(self, field)
results.append(field.to_representation())
return results
from django.contrib.auth import get_user_model
Users = get_user_model()
class Services(models.Model):
name = models.CharField(max_length=125)
class Pref(models.Model):
service = models.ForeignKey("Service", on_delete=models.CASCADE)
user = models.ForeignKey(Users, on_delete=models.CASCADE)
price = models.DecimalField(max_digits=18, decimal_places=2)
$im = new imagick();
$im->setResolution(300, 300);
$im->readImage($srcimg);
$im->setImageFormat('jpeg');
$im->setImageCompression(imagick::COMPRESSION_JPEG);
$im->setImageCompressionQuality(100);
$im->writeImage($targetimg);
$im->clear();
$im->destroy();
$images = new Imagick("test.pdf");
foreach($images as $i=>$image) {
$image->setResolution(300,300);
//etc
$image->writeImage("page".$i.".jpg");
}
$eventManager->attach('dispatch', function (Event $event, Dispatcher $dispatcher) {
if (!$dispatcher->getActionName()) {
$dispatcher->forward([
'controller' => 'error',
'action' => 'notFound',
]);
}
});