CRUD Material - #383
CRUD Material#383Keithy03 wants to merge 3964 commits into
Conversation
…rol documentation
* Allow user to switch to other organization user * Update translations * Update locales and fixed contenttype on fixtures on tests * Add to admin site the impostor model * Fixed impostor logout * Add boostrap classes for close token button text --------- Co-authored-by: Kejebo <kenjen041@gmail.com>
* Validate if do not exists a previous precursor report in task version * Remove precursor reports of the actual month
|
|
||
|
|
||
| class ValidateMaterialCapacitySerializer(serializers.ModelSerializer): | ||
| object = serializers.PrimaryKeyRelatedField(queryset=Object.objects.using( |
There was a problem hiding this comment.
You need to verify the object is a material object type, rewrite the validate function from this serializer and validate the type object == Object.MATERIAL, raise a validationerror and add logger.debug with the info error and return de validate data.
| {data: "id", name: "id", title: "ID", type: "string", visible: false}, | ||
| {data: "code", name: "code", title: "Code", type: "string", visible: true}, | ||
| {data: "name", name: "name", title: "Name", type: "string", visible: true}, | ||
| {data: "actions", name: "actions", title: "Actions", type: "string", visible: true}, |
There was a problem hiding this comment.
You need to include capacity and capacity unit fields in this columns.
| "created_by": request.user.pk}, | ||
| modal_id="#create_obj_form", | ||
| laboratory_pk=lab_pk), | ||
| "update_form": MaterialForm(prefix="update", initial={"laboratory": lab_pk}, |
There was a problem hiding this comment.
Remove the initial parameter in update_form, the instance is already created so is not neccesary to send initial data here.
| laboratory_pk = kwargs.pop('laboratory_pk') | ||
| super(MaterialForm, self).__init__(*args, **kwargs) | ||
| self.fields['object'].required = False | ||
| self.fields['is_container'].initial = True |
There was a problem hiding this comment.
This line can be removed self.fields['is_container'].initial = True and you can define this initial from create_from in view_material_list
| response_data = material_serializer.data | ||
| material_ca_data = material_ca_serializer.data | ||
|
|
||
| # THIS ID SHOULDN'T REPLACE THE MAIN ID(EQUIPMENT OBJECT) |
| if errors: | ||
| raise ValidationError(errors) | ||
|
|
||
| def get_material_ca_serializer(self, instance, request, partial, lab_pk): |
There was a problem hiding this comment.
Complete de name function and variables -- > ca --> capacity.
| material_ca_instance = instance.materialcapacity | ||
| material_ca_serializer = ValidateMaterialCapacitySerializer( | ||
| material_ca_instance, data=data, partial=partial, | ||
| context={"lab_pk": lab_pk}) |
There was a problem hiding this comment.
Why you are sending lab_pk by context if in this serializer is not using this parameter.
|
|
||
| def __init__(self, *args, **kwargs): | ||
| modal_id = kwargs.pop('modal_id') | ||
| laboratory_pk = kwargs.pop('laboratory_pk') |
There was a problem hiding this comment.
laboratory_pk variable is not necessary, just send required data. Also you can copy all fields in MaterialCapacityObjectForm form inside this other form because is a new form just for material crud, the MaterialCapacityObjectForm form will be deleted after this process.
| datatable_inits: datatable_inits, | ||
| add_filter: true, | ||
| relation_render: {'field_autocomplete': 'text' }, | ||
| delete_display: data => data['code'], |
There was a problem hiding this comment.
Name is field better here. delete_display: data => data['name'],
Update the Material Management view to use Gentelella's CRUDAL:
Creation of the API where serializers, material management, and filters were created.
Creation of the view and form for the CRUD.