1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How to fix “ '" is not a valid UUID.”

Discussão em 'Python' iniciado por Stack, Outubro 8, 2024.

  1. Stack

    Stack Membro Participativo

    I want to let user re-order/sort table of content with drag and drop. And whene I push "Submit order" button (after re-order) I have error:

    ValidationError at /save-group-ordering/
    ['“” is not a valid UUID.']
    Request Method: POST
    Request URL: http://127.0.0.1:8000/save-group-ordering/
    Django Version: 3.0.2
    Exception Type: ValidationError
    Exception Value:
    ['“” is not a valid UUID.']

    Traceback Switch to copy-and-paste view
    C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-
    packages\django\db\models\fields\__init__.py in to_python
    return uuid.UUID(**{input_form: value}) …
    ▶ Local vars
    C:\Python 3.7\lib\uuid.py in __init__
    raise ValueError('badly formed hexadecimal UUID string') …
    ▶ Local vars
    During handling of the above exception (badly formed hexadecimal UUID string), another exception occurred:
    C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\core\handlers\exception.py in inner
    response = get_response(request) …
    ▶ Local vars
    C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\core\handlers\base.py in _get_response
    response = self.process_exception_by_middleware(e, request) …
    ▶ Local vars
    C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site- packages\django\core\handlers\base.py in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs) …
    ▶ Local vars
    C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\views\decorators\http.py in inner
    return func(request, *args, **kwargs) …
    ▶ Local vars
    C:\Users\Admin.2\Desktop\taskmanager\tasks\views.py in save_new_ordering
    group = Task.objects.get(lookup_id__exact=lookup_id) …
    ▶ Local vars
    C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\manager.py in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs) …
    ▶ Local vars
    C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\query.py in get
    clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs) …
    ▶ Local vars
    C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\query.py in filter
    return self._filter_or_exclude(False, *args, **kwargs) …
    ▶ Local vars
    C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\query.py in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs)) …
    ▶ Local vars
    C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\sql\query.py in add_q
    clause, _ = self._add_q(q_object, self.used_aliases) …
    ▶ Local vars
    C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\sql\query.py in _add_q
    check_filterable=check_filterable, …
    ▶ Local vars
    C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\sql\query.py in build_filter
    condition = self.build_lookup(lookups, col, value) …
    ▶ Local vars
    C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\sql\query.py in build_lookup


    lookup = lookup_class(lhs, rhs) … ▶ Local vars C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site- packages\django\db\models\lookups.py in init self.rhs = self.get_prep_lookup() … ▶ Local vars C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\lookups.py in get_prep_lookup return self.lhs.output_field.get_prep_value(self.rhs) … ▶ Local vars C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\fields_init_.py in get_prep_value return self.to_python(value) … ▶ Local vars C:\Users\Admin.2\Desktop\taskmanager\ENV\lib\site-packages\django\db\models\fields_init_.py in to_python params={'value': value}, … ▶ Local vars

    I only start work with django and I not understand what I am doing wrong.

    Here is my models.py

    class Task(models.Model):

    project = models.ForeignKey(Project, null=True, on_delete=models.CASCADE)
    title = models.CharField(max_length=300, null=True)
    complete = models.BooleanField(default=False)
    deadline = models.DateField('Deadline of the task (year, month, day)', default=date.today)
    created = models.DateTimeField(auto_now_add=True,null=True)
    lookup_id = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True)
    order = models.IntegerField(blank=False, default=100_000)

    def __str__(self):
    return self.title

    def deadline_func(self):
    days = self.deadline - date.today()
    return days


    Here is my urls.py

    from django.urls import path
    from . import views

    urlpatterns = [
    path('' , views.projects_list, name="list"),
    path('create_project/' , views.createProject, name="create_project"),

    path('deadline_project/<str:pk>' , views.deadlineProject, name="deadline_project"),

    path('update_project/<str:pk>' , views.updateProject, name="update_project"),
    path('delete_project/<str:pk>' , views.deleteProject, name="delete_project"),
    path('create_task/<str:pk>' , views.createTask, name="create_task"),

    path('save-group-ordering/', views.save_new_ordering, name='save-group-oldering'),

    path('deadline_task/<str:pk>' , views.deadlineTask, name="deadline_task"),

    path('update_task/<str:pk>' , views.updateTask, name="update_task"),
    path('delete_task/<str:pk>' , views.deleteTask, name="delete_task"),
    ]


    Here is my views.py

    @require_POST
    def save_new_ordering(request):
    form = OrderingForm(request.POST)

    if form.is_valid():
    ordered_ids = form.cleaned_data["ordering"].split(',')

    with transaction.atomic():
    current_order = 1
    for lookup_id in ordered_ids:
    group = Task.objects.get(lookup_id__exact=lookup_id)
    group.order = current_order
    group.save()
    current_order += 1

    return redirect('/')


    Here is my forms.py

    class TaskForm(forms.ModelForm):

    class Meta:
    model = Task
    fields = '__all__'

    class OrderingForm(forms.Form):
    ordering = forms.CharField()


    Here is my html

    <table class="raz">

    <tbody id="groups">
    {% for task in project.task_set.all %}



    <tr data-lookup="{{ folder.lookup_id }}">
    <td style="width: 50px;"><span class="handle"><img src=" static/images/Up_Down.png " alt="Up_Down_icon"></span></td>

    {% if task.complete == True %}
    <td style="width: 50px;"class="ch"><input class="checkbox" type="checkbox" name="complete" id="id_complete" checked ></td>
    {% else %}
    <td style="width: 50px;"><input class="checkbox" type="checkbox" name="complete" id="id_complete" ></td>
    {% endif %}

    <td style="width: 550px;"><p>{{task.title}}</p></td>

    <td style="width: 50px;"><a class="calendar" href="{% url 'deadline_task' task.id %}">
    <img src=" static/images/calendar.png " alt="calendar_icon">
    </a></td>

    <td style="width: 50px;"><a href="{% url 'update_task' task.id %}" class="edittask">
    <img src=" static/images/pencil_icon.png " alt="pencil_icon">
    </a></td>

    <td style="width: 50px;"><a href="{% url 'delete_task' task.id %}" class="deletetask">
    <img src=" static/images/trash.png " alt="trash_icon">
    </a></td>

    </tr>

    {% endfor%}
    </tbody>

    </table>


    <form id="orderingForm" method="post" action="{% url 'save-group-oldering' %}">
    {% csrf_token %}
    <input type="hidden" id="orderingInput" name="ordering">
    </form>

    <button id="saveOrdering">Save ordering</button>

    Continue reading...

Compartilhe esta Página