public static function getFields() { return ['name' => ['class' => CharField::className()], 'place' => ['class' => OneToOneField::className(), 'modelClass' => Place::className(), 'primary' => true]]; }
public static function getFields() { return ['name' => ['class' => CharField::className()], 'restaurant' => ['class' => OneToOneField::className(), 'modelClass' => Restaurant::className(), 'reversed' => true]]; }
public function exportCsv(array $data = []) { $qs = $this->getQuerySet($this->getModel()); if (isset($data['models'])) { $qs->filter(['pk__in' => $data['models']]); } $exportData = []; $header = []; $modelsIterator = $qs->batch(100); $noExportFieldsClassName = [ForeignField::className(), HasManyField::className(), ManyToManyField::className(), OneToOneField::className()]; foreach ($modelsIterator as $models) { foreach ($models as $model) { $fields = $model->getFieldsInit(); $line = []; foreach ($fields as $attribute => $field) { if (in_array($field->className(), $noExportFieldsClassName)) { continue; } $verboseName = $field->getVerboseName($model); if (!array_key_exists($verboseName, $header)) { $header[$verboseName] = $verboseName; } $line[] = $model->{$attribute}; } $exportData[] = $line; } } $this->forceCsv($header, $exportData); }