Questions tagged [django-model-field]
112 questions
1
vote
1 answer
How to pass concatenated functions as a argument in django model method
I am trying to pass timezone.now() + timedelta(days=-2) and timezone.now() as arguments in django model method but am getting
def performance(user, timezone.now() + timedelta(days=-2), timezone.now()):
…

Thaddeaus Iorbee
- 63
- 9
1
vote
1 answer
Model form data not showing up in database. Form not saving data
The form I created is not inserting the data into my database table. As far as I can tell I've done everything correctly but it still refuses to save into the database. Instead it "post" in the console and clears the form fields without creating…

Houston Khanyile
- 75
- 8
1
vote
1 answer
Using integers and strings together in Django choice field
I am trying to use the new Enum types in the latest Django version for the choice field. Specifically I am trying to store the various states of United States as follows:
class States(models.TextChoices):
ALABAMA = 'AL', 'Alabama'
ALASKA =…

Amistad
- 7,100
- 13
- 48
- 75
1
vote
1 answer
How can I upload multiple files in to a Django model?
I'm trying to make an LMS system with Django and now I need to upload multiple pdf files to the curriculum of the class. I can upload one file with the OnetoOne field in the Django model but not more. When I try to add another material for the same…

Sumeth Sathnindu
- 323
- 4
- 15
1
vote
1 answer
Override Field Option on Inherited Model in Django
I've found similar questions and answers, but none seems exactly right. I've got an abstract base model like so:
class BaseModel(models.Model):
timestamp = models.DateTimeField(auto_now_add=True)
modified =…

nicorellius
- 3,715
- 4
- 48
- 79
1
vote
1 answer
Perfom Django Validation for field that is NOT part of form
I would like to raise a ValidationError based on one of the fields in my Django model, without having the respective filed as part of a ModelForm. What I found after googling a bit is the concept of validators for models. So I tried to do the…

Rosi98
- 107
- 9
1
vote
1 answer
check that the dates are entered correctly in a form
I have a form to create events and I want to check that the dates are correct: end date greater than the start date or dates not before the actual date, etc...
I was checking on the internet if there was any check with django for…

carciofinospinoso
- 63
- 1
- 8
1
vote
1 answer
How to filter by field name in model manager (NameError)
models.py
class StudentProfile(models.Model):
student = models.OneToOneField(
User, related_name='student', primary_key=True, parent_link=True, on_delete=models.CASCADE)
membership_end = models.DateTimeField(
verbose_name="Membership…

Lawrence DeSouza
- 984
- 5
- 16
- 34
1
vote
3 answers
Django - Which model field for dir path?
I need to define a field in my Model, which is supposed to host a valid dir path on server-side.
Basically just a string which should be:
1) a formally valid unix-like dir path
2) an existing dir path
Tried with FilePathField with options…

zeroquaranta
- 392
- 4
- 16
1
vote
1 answer
How to display CHOICES in Django ModelForm
I have a policy_category model with 16 categories.
I have a Response model to record survey answers. The model includes a field to record the respondent's 1-5 rating for each of the policy categories. (policy_1_rank..policy_16_rank, etc.)
I can't…

jm2288
- 53
- 8
1
vote
1 answer
Every field in Django modelform shows "Select a valid choice. That choice is not one of the available choices."
I've already read many other threads complaining about this error message but I still can't figure this out. I try removing the fields that give the error, and the error message just moves to another field the next time I try to submit. They are…

jm2288
- 53
- 8
1
vote
2 answers
ImportError: cannot import name 'get_core_apps' in Django Oscar Module
I am getting error when I am installing Django Oscar Module in my Project, it's giving me this error
from oscar import get_core_apps
ImportError: cannot import name 'get_core_apps'
Here are my settings.py file...
from oscar import…

msginfosys
- 57
- 11
1
vote
1 answer
Django form: reference fields from foreign key
I'm making a task tracker webapp (the full source code is also available) and I have a database structure where each task has a title, a description, and some number of instances, that can each be marked incomplete/incomplete:
class…

Solomon Ucko
- 5,724
- 3
- 24
- 45
1
vote
3 answers
How to save a thumbnail to default_storage(AWS S3) after converting it in Django views.py?
I have a an HTML form that allows images upload. I want to save the original image to S3 storage and then convert it to thumbnail and save the thumbnail to the same storage.
I could only save the original image but after converting it to thumbnail…

Hossam Mohamed
- 126
- 1
- 7
1
vote
1 answer
Django Abstract Class change behaviour according to actual class
I think following code explains what I'm trying to do
from django.db import models
class MyBaseClass(models.Model):
type = models.IntegerField()
class Meta:
abstract = True
def save(self, *args, **kwargs):
self.type =…

EralpB
- 1,621
- 4
- 23
- 36