Questions tagged [django-model-field]
112 questions
2
votes
1 answer
How do I take input as String and save as Binary in Django using Django REST Framework?
Here is my model:
class Example(models.Model):
file = S3PrivateFileField()
text = models.TextField(null=True, blank=True)
binary = models.BinaryField(null=True, blank=True)
and here is the serializer:
class…

Rafi
- 467
- 6
- 17
2
votes
1 answer
How to make django model ManyToMany field empty initially?
I'm having two related models as follows.
class Book(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author)
isbn =models.CharField(max_length=15)
class Lending(models.Model):
member_id =…

Indika Rajapaksha
- 1,056
- 1
- 14
- 36
2
votes
1 answer
No exception raised when saving an empty field with null=False - Django
I have the following model:
class User(models.Model):
email = models.EmailField(max_length=254, null=False, unique=True)
referral_code = models.CharField(max_length=10, null=False, unique=True)
And used the Django shell to save a user…

Rob
- 617
- 8
- 21
2
votes
1 answer
Django: made error in models.py and migrated, tried to fix the error but django doesnt see any change in models.py
So I made the following silly error in models.py:
caption_on = models.BooleanField(default='true')
which gave me the following error when i ran 'makemigrations' and 'migrate'
django.core.exceptions.ValidationError: ["'true' value must be either…

Jules
- 25
- 2
- 4
1
vote
2 answers
Is there an efficient way to recursively query a Django model manytomany field?
Given this model:
class Role(models.Model):
title = models.CharField(max_length=255, verbose_name='Role Title')
parents = models.ManyToManyField("self", symmetrical=False)
skills = models.ManyToManyField(Skill)
What is the most…

Phear46
- 15
- 6
1
vote
1 answer
Django relation of models
I have an e-commerce project and I stuck at admin view.
I have 2 models, namely Order and OrderItem. They are connected with FK relationship, and when Order is created I create both Order and related OrderItems in my admin page.
Orders in admin…

bailofwZ
- 123
- 1
- 10
1
vote
1 answer
Django model property field calculated with field from another child model
class BusinessFunction(models.Model):
name = models.CharField(max_length=200)
priority_rating = models.PositiveIntegerField(null=True, blank=True)
location = models.CharField(max_length=200)
network_service_related =…

ji.sein
- 35
- 1
- 5
1
vote
1 answer
Django model field bug? "value too long for type character varying(3)" error
I am declaring two choice fields for my django model in the same manner but one of them somehow bugs into having maxlength=3. I am using a PostgreSQL database.
Here is how I declare the fields:
class AssignmentAd(models.Model):
class…

Windfish
- 68
- 7
1
vote
1 answer
IntegrityError Django Model
I'm trying to implement a foreign key at one of my tables, but I keep getting this error all the time:
null value in column "user_id" of relation "application_application" violates not-null constraintDETAIL: Failing row contains (3, 2022-09-09, San…

Adivhaho Mavhungu
- 384
- 3
- 8
1
vote
0 answers
What is the most Django-appropriate way to combine multiple database columns into one model field?
I have several times come across a want to have a Django model field that comprises multiple database columns, and am wondering what the most Django way to do it would be.
Three use cases come specifically to mind.
I want to provide a field that…

Adam Barnes
- 2,922
- 21
- 27
1
vote
0 answers
how to add form field or model field which support all types characters?
I have a UserInfo model which contains various fields. In the username_in_bangla field I want the user to give his/her name in Bangla text.
models.py
class UserInfo(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
…

Osman Goni
- 15
- 7
1
vote
2 answers
Availability Schedule field in Django Models?
I am quite new to Django and I'm trying to build a web application where some users will be able to input their available weekly schedule and also show at what times of a day they are available. The picture below(this is just front-end part) shows…

Ixion Chowdhury
- 140
- 11
1
vote
1 answer
How to resolve this "Invalid default value for a django.models field error"?
I am creating a student model which records homework details of a student. It works in a way that student has been given work to do at home with some deadlines of days or hours. When I migrate, I get this error I am getting this error
File…

Noor Ibrahim
- 51
- 8
1
vote
1 answer
Django ModelField custom attribute
Very simple question: can you make a custom attribute for a Field?
I have a Customer model with a bunch of Fields. Charfields, ForeignKeys,IntegerFields, BooleanFields etc. etc.
When the form gets submitted for a new customer I want to export the…

Samoht
- 39
- 6
1
vote
1 answer
Django - how to force user to select a certain amount of options in a checbox modelform?
I'm making a simple survey built around a modelform:
models.py
class Fruits(models.Model):
author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
title = models.CharField(max_length=200, default='')
text =…

LarsLill
- 141
- 1
- 10