django-models

Populate Django Model with for-loop

Populate Django Model with for-loop Question: I have a model Task which I want to populate with a for loop. In a list I have the tasks that should be passed into the model. My model has actually more than three tasks (Below I have shown only three). The list will also have varying number …

Total answers: 1

how to convert DateField field while returning a filtered result in DJANGO

how to convert DateField field while returning a filtered result in DJANGO Question: I have the following table in django: models.py class Activity(models.Model) name = models.CharField(max_length=50) date_created = models.DateField() here is the way i create an instance of that table from datetime import date Activity.objects.create(name="Foo", date_created=str(date.today())) I know that auto_now_add=True can be used to store …

Total answers: 1

reverse accessor model clashing Django Web App

reverse accessor model clashing Django Web App Question: from django.db import models from django.contrib.auth.models import AbstractUser class Customer(AbstractUser): address_line = models.CharField(max_length=255) city = models.CharField(max_length=255) postal_code = models.CharField(max_length=10) phone_number = models.CharField(max_length=20) origin_country = models.CharField(max_length=255) profile_picture = models.ImageField(upload_to=’customer_profile_pics’, null=True, blank=True) class Chef(AbstractUser): address_line = models.CharField(max_length=255) city = models.CharField(max_length=255) postal_code = models.CharField(max_length=10) phone_number = models.CharField(max_length=20) origin_country = models.CharField(max_length=255) …

Total answers: 1

How to do model data validation in django

How to do model data validation in django Question: I would like when creating and editing a product to validate the data directly in the model in adminpanel and forms and if validated return an error more or less like this: models.py class Book(Product): GENRE_CHOICES = ( (‘Fantasy’, ‘Fantasy’), (‘Sci-Fi’, ‘Sci-Fi’), (‘Romance’, ‘Romance’), (‘Historical Novel’, …

Total answers: 2

Extending a base model in django

Extending a base model in django Question: I want to create base model for my questions named Question and extend it by any other question types: class Question(models.Model): questionnaire = models.ForeignKey(to=’Questionnaire’, on_delete=models.CASCADE, related_name=’questions’) question = models.TextField() description = models.TextField(null=True, blank=True) media = models.FileField(upload_to=’medias’, blank=True, null=True) is_required = models.BooleanField(default=False) def __str__(self): return f'{self.questionnaire.name} – {self.question}’ and …

Total answers: 1

Populate readonly nested serializer

Populate readonly nested serializer Question: I’m using ModelViewSets and I have nested serializer for these models. class Profile(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) user = models.OneToOneField(User, on_delete=models.CASCADE) place = models.OneToOneField(Place, on_delete=models.DO_NOTHING) bio = models.TextField(null=True) class User(AbstractBaseUser, PermissionsMixin): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) email = models.EmailField(_(’email address’), unique=True) first_name = models.CharField(max_length=150, blank=True) is_staff = models.BooleanField(default=False) is_active …

Total answers: 2

nothing happens after running python manage.py shell < script.py

nothing happens after running python manage.py shell < script.py Question: This is my first time trying to run a script. I’m trying to hash previously stored plain text in my db. Anyway I created script.py file in my project folder it doesn’t seem to do anything what am I missing? The command I’m running in …

Total answers: 1