Showing
4 changed files
with
31 additions
and
7 deletions
@@ -14,7 +14,6 @@ from .utils import contador | @@ -14,7 +14,6 @@ from .utils import contador | ||
14 | 14 | ||
15 | class EdictoViewSet(mixins.CreateModelMixin, | 15 | class EdictoViewSet(mixins.CreateModelMixin, |
16 | mixins.RetrieveModelMixin, | 16 | mixins.RetrieveModelMixin, |
17 | - mixins.UpdateModelMixin, | ||
18 | mixins.ListModelMixin, | 17 | mixins.ListModelMixin, |
19 | viewsets.GenericViewSet): | 18 | viewsets.GenericViewSet): |
20 | 19 | ||
@@ -36,9 +35,9 @@ class EdictoViewSet(mixins.CreateModelMixin, | @@ -36,9 +35,9 @@ class EdictoViewSet(mixins.CreateModelMixin, | ||
36 | usuario_movimiento=usuario, | 35 | usuario_movimiento=usuario, |
37 | ) | 36 | ) |
38 | 37 | ||
39 | - def update(self, request, *args, **kwargs): | 38 | + def partial_update(self, request, *args, **kwargs): |
40 | instance = self.get_object() | 39 | instance = self.get_object() |
41 | - serializer = self.get_serializer(instance, data=request.data) | 40 | + serializer = self.get_serializer(instance, data=request.data, partial=True) |
42 | serializer.is_valid(raise_exception=True) | 41 | serializer.is_valid(raise_exception=True) |
43 | 42 | ||
44 | edicto = request.data.get('cuerpo_edicto') | 43 | edicto = request.data.get('cuerpo_edicto') |
1 | +# Generated by Django 4.1.9 on 2023-09-15 12:36 | ||
2 | + | ||
3 | +from django.db import migrations, models | ||
4 | +import uuid | ||
5 | + | ||
6 | + | ||
7 | +class Migration(migrations.Migration): | ||
8 | + | ||
9 | + dependencies = [ | ||
10 | + ('edicto', '0015_edicto_usuario_movi'), | ||
11 | + ] | ||
12 | + | ||
13 | + operations = [ | ||
14 | + migrations.RemoveField( | ||
15 | + model_name='edicto', | ||
16 | + name='id', | ||
17 | + ), | ||
18 | + migrations.AlterField( | ||
19 | + model_name='edicto', | ||
20 | + name='uuid', | ||
21 | + field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True), | ||
22 | + ), | ||
23 | + ] |
@@ -25,7 +25,7 @@ class Precio (models.Model): | @@ -25,7 +25,7 @@ class Precio (models.Model): | ||
25 | 25 | ||
26 | 26 | ||
27 | class Edicto(models.Model): | 27 | class Edicto(models.Model): |
28 | - uuid = models.UUIDField(unique=True, editable=False, default=uuid4) | 28 | + uuid = models.UUIDField(unique=True, editable=False, default=uuid4, primary_key=True) |
29 | usuario = models.ForeignKey(Usuario, on_delete=models.CASCADE, verbose_name='Usuario') | 29 | usuario = models.ForeignKey(Usuario, on_delete=models.CASCADE, verbose_name='Usuario') |
30 | cuerpo_edicto = models.TextField(blank=False, null=False) | 30 | cuerpo_edicto = models.TextField(blank=False, null=False) |
31 | archivo = models.FileField(upload_to="uploads/%Y/%m/%d/", null=False, blank=False) | 31 | archivo = models.FileField(upload_to="uploads/%Y/%m/%d/", null=False, blank=False) |
@@ -15,8 +15,7 @@ class EdictoSerializer(serializers.ModelSerializer): | @@ -15,8 +15,7 @@ class EdictoSerializer(serializers.ModelSerializer): | ||
15 | 15 | ||
16 | class Meta: | 16 | class Meta: |
17 | model = Edicto | 17 | model = Edicto |
18 | - fields = ('uuid', | ||
19 | - 'usuario', | 18 | + fields = ('usuario', |
20 | 'usuario_movimiento', | 19 | 'usuario_movimiento', |
21 | 'estado', | 20 | 'estado', |
22 | 'cuerpo_edicto', | 21 | 'cuerpo_edicto', |
@@ -31,6 +30,9 @@ class EdictoSerializer(serializers.ModelSerializer): | @@ -31,6 +30,9 @@ class EdictoSerializer(serializers.ModelSerializer): | ||
31 | 'fecha_modificacion' | 30 | 'fecha_modificacion' |
32 | 31 | ||
33 | ) | 32 | ) |
33 | + extra_kwargs = { | ||
34 | + 'archivo': {'read_only': True} | ||
35 | + } | ||
34 | 36 | ||
35 | read_only_fields = ('usuario', 'usuario_movimiento', | 37 | read_only_fields = ('usuario', 'usuario_movimiento', |
36 | 'fecha_publicacion', 'cantidad_palabras', | 38 | 'fecha_publicacion', 'cantidad_palabras', |
@@ -40,7 +42,7 @@ class EdictoSerializer(serializers.ModelSerializer): | @@ -40,7 +42,7 @@ class EdictoSerializer(serializers.ModelSerializer): | ||
40 | 42 | ||
41 | def to_representation(self, instance): | 43 | def to_representation(self, instance): |
42 | data = super().to_representation(instance) | 44 | data = super().to_representation(instance) |
43 | - if instance.fecha_modificacion is not None and self.context['request'].method == 'PUT': | 45 | + if instance.fecha_modificacion is not None and self.context['request'].method == 'PATCH': |
44 | data['fecha_modificacion'] = instance.fecha_modificacion | 46 | data['fecha_modificacion'] = instance.fecha_modificacion |
45 | else: | 47 | else: |
46 | data['fecha_modificacion'] = None | 48 | data['fecha_modificacion'] = None |
-
Please register or login to post a comment