Category : django-orm

Let’s say I have the following Django models: class Toolbox(models.Model): name = models.CharField(max_length=255) tools = models.ManyToManyField("Tool") class Tool(models.Model): class Size(models.TextChoices): SMALL = "S" MEDIUM = "M" LARGE = "L" name = models.CharField(max_length=255) size = models.CharField(max_length=10, choices=Size.choices) I have a function to get all small tools for each toolbox. The @queries_disabled() comes from django-zen-queries to ensure ..

Read more

Have this model: class Review(models.Model): RATING_VALUES = [ (‘1’, ‘Ужасно’), (‘2’, ‘Плохо’), (‘3’, ‘Сносно’), (‘4’, ‘Хорошо’), (‘5’, ‘Отлично’), ] spare_part = models.ForeignKey(‘SparePart’, on_delete=models.PROTECT, verbose_name="Запчасть") mileage = models.SmallIntegerField(verbose_name="Пробег, тыс.км") car_brand = models.ForeignKey(‘CarBrand’, on_delete=models.PROTECT, verbose_name="Марка авто") car_model = models.ForeignKey(‘CarModel’, on_delete=models.PROTECT, verbose_name="Модель авто") owner = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="Владелец") rating = models.CharField(max_length=1, choices=RATING_VALUES, verbose_name="Рейтинг", default=3) testimonial = models.TextField(max_length=1000, blank=True, ..

Read more

How can I find out the type by accessing the column of the index of the models.all() result?? My code is like this: def qtj(result_model): for index in result_model: print(‘index : ‘, index) for column in index: print(f’column : {column} type:{type(column)}’) but this at index : index : {‘board_seq’: Decimal(’15’), ‘board_title’: ‘제목’, ‘board_content’: ‘내용’, ‘board_writer’: ..

Read more

Previously, I did implement the ExpressionWrapper to create a custom filter, It’s working fine in the postgresql, but when I did run test with sqlite3, then the error said django.db.utils.DatabaseError: Invalid connector for timedelta: *.. class AccessDurationQuerySet(models.QuerySet): def filter_expiration(self, is_expired: bool = False): """ To filter whether AccessDuration already expired or yet. don’t use the ..

Read more

I’m developing a scoring system for posts on a website. It considers other relational fields (comments, views, and reactions_emojis) to have a more insightful way to order the results. But since it’s not desirable to have popular posts, but too old, on the front page, I decided to consider the post creation time. The problem ..

Read more

I want to save the details of the user in the database table when he or she click the ‘Apply Now’ button.Some details of the user is stored in the database using django user model and the remaining details stored in the database using another model named ‘IndividualProfile’.Job details are stored in another model named ..

Read more