django-rest-framework

Django 'QuerySet' object has no attribute 'startswith'

Django 'QuerySet' object has no attribute 'startswith' Question: I’m new to Django and I created function to allow admin to create users accounts. I used a password generator + make_password() function to hash the password. Now it’s sending the plain password to users email and storing it in the database hashed, I used check_password() to …

Total answers: 2

How to auto create foreingKey object (python with django)

How to auto create foreingKey object (python with django) Question: I’m creating a simple rest api This is my actual result from devices, i create first the group and options, and then associate, but i want to create the options at the same time i create the device. My result from devices right now [ …

Total answers: 2

How to return object insted of id's, and auto create foreingKey object (get python with django)

How to return object insted of id's, and auto create foreingKey object (get python with django) Question: I’m creating a simple rest api This is my actual result from devices [ { "id_device": "a099d2ce-812b-4d85-8c8b-cfe71057fbe7", "name": "Interruptor 4", "identifier": "teste1", "group": "39407ef6-1a3e-4965-9b61-96f6c40b76b3", "options": [ "1b383a37-5229-4ae0-9649-f76aa32eeda0", "4ff5406a-8c7b-4517-9ec0-14fd4f68f30b", "a541216d-f509-4461-85ca-444491ac9217", "3debe828-edd6-4d83-bfd8-2776a1594380" ] }, { "id_device": "dc9f672f-6759-4b1f-ac65-e3d78e09833d", "name": "teste", "identifier": …

Total answers: 1

How to show and keep the last record in Django

How to show and keep the last record in Django Question: I’m new to Django I hope I’m making sense. I have two models: Usecase and Usecase_progress. I’m creating a page where I can see a list of all the use cases with their information + the usecase progress for each use case gets recorded. …

Total answers: 1

raise FieldError( django.core.exceptions.FieldError: Cannot resolve keyword 'is_active' into field

raise FieldError( django.core.exceptions.FieldError: Cannot resolve keyword 'is_active' into field Question: I got this doubt, I’m creating a custom user model in Django and at the moment to apply the migrations, it throws me this error raise FieldError( django.core.exceptions.FieldError: Cannot resolve keyword ‘is_active’ into field. Choices are: cargo, centro, centro_id, direccion, fecha_nacimiento, id, imagen_perfil, last_login, logentry, …

Total answers: 1

Django-rest-framework IF statement in post method is not executing

Django-rest-framework IF statement in post method is not executing Question: (I will provide full code at the bottom) I am trying to create an API view with django rest framework. I wanted to create a login API so I was first testing out on how to check if a data exists in a field in …

Total answers: 1

I want to send and an otp with REST Framework

I want to send and an otp with REST Framework Question: File "/home/ali/MAKEEN/makeen-tasks/ali/tasks/user/api/services.py", line 24, in generate_otp self.otp = str(randint(100000, 999999)) AttributeError: ‘str’ object has no attribute ‘otp’ self._otp = str(randint(100000, 999999)) AttributeError: ‘str’ object has no attribute ‘_otp’ [25/Feb/2023 14:04:01] "POST /login1/ HTTP/1.1" 500 101590 services.py class OTPGenerator: def __init__(self, phone_number): self.phone_number = phone_number …

Total answers: 2

Django queryset show english translations

Django queryset show english translations Question: This is my Django models.py: from django.db import models class Blog(models.Model): pub_date = models.DateTimeField(‘date published’) def __str__(self): return self.pub_date class LanguagesCode(models.Model): code = models.CharField(max_length=5) def __str__(self): return self.code class BlogTranslation(models.Model): name = models.CharField(max_length=250) content = models.TextField(blank=True, null=True) blog_id = models.ForeignKey(Blog, related_name=’translations’, on_delete=models.CASCADE) language_code = models.ForeignKey(LanguagesCode, related_name=’languages’, on_delete=models.DO_NOTHING) class Meta: …

Total answers: 2