mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-05 06:08:46 -05:00
working on model select
This commit is contained in:
@@ -12,50 +12,50 @@
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import { exists, mapValues } from '../runtime';
|
||||
import { mapValues } from '../runtime';
|
||||
import type { OpenDataVersion } from './OpenDataVersion';
|
||||
import {
|
||||
OpenDataVersion,
|
||||
OpenDataVersionFromJSON,
|
||||
OpenDataVersionFromJSONTyped,
|
||||
OpenDataVersionToJSON,
|
||||
} from './';
|
||||
} from './OpenDataVersion';
|
||||
|
||||
/**
|
||||
* Moves `UniqueValidator`'s from the validation stage to the save stage.
|
||||
It solves the problem with nested validation for unique fields on update.
|
||||
|
||||
If you want more details, you can read related issues and articles:
|
||||
https://github.com/beda-software/drf-writable-nested/issues/1
|
||||
http://www.django-rest-framework.org/api-guide/validators/#updating-nested-serializers
|
||||
|
||||
Example of usage:
|
||||
```
|
||||
class Child(models.Model):
|
||||
field = models.CharField(unique=True)
|
||||
|
||||
|
||||
class Parent(models.Model):
|
||||
child = models.ForeignKey('Child')
|
||||
|
||||
|
||||
class ChildSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Child
|
||||
|
||||
|
||||
class ParentSerializer(NestedUpdateMixin, serializers.ModelSerializer):
|
||||
child = ChildSerializer()
|
||||
|
||||
class Meta:
|
||||
model = Parent
|
||||
```
|
||||
|
||||
Note: `UniqueFieldsMixin` must be applied only on the serializer
|
||||
which has unique fields.
|
||||
|
||||
Note: When you are using both mixins
|
||||
(`UniqueFieldsMixin` and `NestedCreateMixin` or `NestedUpdateMixin`)
|
||||
you should put `UniqueFieldsMixin` ahead.
|
||||
* It solves the problem with nested validation for unique fields on update.
|
||||
*
|
||||
* If you want more details, you can read related issues and articles:
|
||||
* https://github.com/beda-software/drf-writable-nested/issues/1
|
||||
* http://www.django-rest-framework.org/api-guide/validators/#updating-nested-serializers
|
||||
*
|
||||
* Example of usage:
|
||||
* ```
|
||||
* class Child(models.Model):
|
||||
* field = models.CharField(unique=True)
|
||||
*
|
||||
*
|
||||
* class Parent(models.Model):
|
||||
* child = models.ForeignKey('Child')
|
||||
*
|
||||
*
|
||||
* class ChildSerializer(UniqueFieldsMixin, serializers.ModelSerializer):
|
||||
* class Meta:
|
||||
* model = Child
|
||||
*
|
||||
*
|
||||
* class ParentSerializer(NestedUpdateMixin, serializers.ModelSerializer):
|
||||
* child = ChildSerializer()
|
||||
*
|
||||
* class Meta:
|
||||
* model = Parent
|
||||
* ```
|
||||
*
|
||||
* Note: `UniqueFieldsMixin` must be applied only on the serializer
|
||||
* which has unique fields.
|
||||
*
|
||||
* Note: When you are using both mixins
|
||||
* (`UniqueFieldsMixin` and `NestedCreateMixin` or `NestedUpdateMixin`)
|
||||
* you should put `UniqueFieldsMixin` ahead.
|
||||
* @export
|
||||
* @interface OpenDataCategory
|
||||
*/
|
||||
@@ -104,12 +104,24 @@ export interface OpenDataCategory {
|
||||
readonly createdBy: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given object implements the OpenDataCategory interface.
|
||||
*/
|
||||
export function instanceOfOpenDataCategory(value: object): boolean {
|
||||
if (!('id' in value)) return false;
|
||||
if (!('version' in value)) return false;
|
||||
if (!('slug' in value)) return false;
|
||||
if (!('name' in value)) return false;
|
||||
if (!('createdBy' in value)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
export function OpenDataCategoryFromJSON(json: any): OpenDataCategory {
|
||||
return OpenDataCategoryFromJSONTyped(json, false);
|
||||
}
|
||||
|
||||
export function OpenDataCategoryFromJSONTyped(json: any, ignoreDiscriminator: boolean): OpenDataCategory {
|
||||
if ((json === undefined) || (json === null)) {
|
||||
if (json == null) {
|
||||
return json;
|
||||
}
|
||||
return {
|
||||
@@ -118,27 +130,23 @@ export function OpenDataCategoryFromJSONTyped(json: any, ignoreDiscriminator: bo
|
||||
'version': OpenDataVersionFromJSON(json['version']),
|
||||
'slug': json['slug'],
|
||||
'name': json['name'],
|
||||
'description': !exists(json, 'description') ? undefined : json['description'],
|
||||
'comment': !exists(json, 'comment') ? undefined : json['comment'],
|
||||
'description': json['description'] == null ? undefined : json['description'],
|
||||
'comment': json['comment'] == null ? undefined : json['comment'],
|
||||
'createdBy': json['created_by'],
|
||||
};
|
||||
}
|
||||
|
||||
export function OpenDataCategoryToJSON(value?: OpenDataCategory | null): any {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
if (value === null) {
|
||||
return null;
|
||||
if (value == null) {
|
||||
return value;
|
||||
}
|
||||
return {
|
||||
|
||||
'version': OpenDataVersionToJSON(value.version),
|
||||
'slug': value.slug,
|
||||
'name': value.name,
|
||||
'description': value.description,
|
||||
'comment': value.comment,
|
||||
'version': OpenDataVersionToJSON(value['version']),
|
||||
'slug': value['slug'],
|
||||
'name': value['name'],
|
||||
'description': value['description'],
|
||||
'comment': value['comment'],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user