const editPatient = useModal({
component: PatientEditForm,
attrs: {
patientId: "",
afterEdit() {
console.log('dfdfdf');
},
},
});
function openEditForm(id: string) {
editPatient.patchOptions({
attrs: {
patientId: id,
},
});
editPatient.open();
};
<template #item-actions="{ id }">
<button class="mx-4" @click="openEditForm(id)">
<i class="fa-solid fa-pen-to-square"></i>
</button>
</template>
class ProductImagesSerializers(serializers.ModelSerializer):
class Meta:
model = ProductImage
fields = '__all__'
class ProductListSerializer(serializers.ModelSerializer):
images = ProductImagesSerializers(many = True, read_only = True)
class Meta:
model = Product
fields = ['id', 'name', 'slug', 'price', 'category', 'images']
read_only_fields = fields
class CustomUser(AbstractBaseUser, PermissionsMixin):
USER_TYPE_CHOICES = (
(1, 'customer'),
(2, 'manufacturer'),
(3, 'seller'),
)
name = models.CharField(max_length=50, null=True, blank=True)
phone = models.CharField(max_length=12, verbose_name='Телефон')
email = models.EmailField('Адрес электронной почты', unique=True)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(default=timezone.now)
user_type = models.PositiveSmallIntegerField(choices=USER_TYPE_CHOICES)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
objects = CustomUserManager()
def get_scope(self):
arr = []
arr.append(self.get_user_type_display())
return arr
def __str__(self):
return self.email
class UserSerializer(serializers.ModelSerializer):
user_type = serializers.ListField(source='get_scope')
# scope = serializers.CharField(source='get_user_type_display')
def create(self, validated_data):
return get_user_model().objects.create_user(**validated_data)
class Meta:
model = get_user_model()
fields = ('email', 'password', 'phone', 'name', 'user_type')
extra_kwargs = {
'password': {'write_only': True, 'min_length': 8},
}
class CompanyList(generics.ListCreateAPIView):
queryset = Company.objects.all()
serializer_class = CompanySerializer
def get_queryset(self):
"""
Фильтруем компании по пользователю который отправил запрос
"""
user = self.request.user
return Company.objects.filter(user=user)