django-models Questions

3

Solved

Context: I'm building a car dealership app using Django 3.1.4, and trying to implement a feature where by every time a new ad is created, so is a new folder (via the upload_to method) within /media...

4

I have this model: class Invoice(models.Model): owner = models.ForeignKey(settings.AUTH_USER_MODEL) data = models.TextField(default=None, blank=True, null=True) number = models.PositiveIntegerF...
Dupuy asked 25/11, 2015 at 17:8

5

Solved

How can you check the type of a many-to-many-field in django? I wanted to do it this way: import django field.__class__ == django.db.models.fields.related.ManyRelatedManager This doesn't work...

4

What is the difference between auto_now_add and timezone.now (as default value) for models in Django? Example: create_date = models.DateTimeField(auto_now_add=True) and create_date = models.Dat...
Supat asked 27/11, 2019 at 16:32

2

Solved

How do I check if there are any ManyToMany field objects related to my model object? For example, I have a model: class Category(models.Model): related_categories = models.ManyToManyField('self'...
Mcgee asked 8/11, 2018 at 10:57

4

I am trying to get display names of choices when using annotate, but I haven't been able to figure out. I have the following query: Survey.objects.values('what').annotate(count=Count('why')).order...
Extravagancy asked 2/4, 2015 at 19:24

4

Solved

I have a model having choices field. I want to fetch the choices options in a list. How can I achieve that? OPTIONS = ( ('COOL', 'COOL'), ('WARM', 'WARM'), ) class My_Model(models.Model): option...
Hogen asked 8/7, 2021 at 12:28

5

Solved

I want my application to have default data such as user types. What's the most efficient way to manage default data after migrations? It needs to handle situations such as, after I add a new table,...
Johannajohannah asked 28/9, 2016 at 6:21

4

Solved

I'm using Django and Python 3.7. I have this code article = get_article(id) ... article.label = label article.save(update_fields=["label"]) Sometimes I get the following error on my "save" line ...
Total asked 22/5, 2019 at 14:22

2

I am getting this error django.core.exceptions.FieldError: Unsupported lookup 'icontains' for ForeignKey or join on the field not permitted Below is models.py: class Author(models.Model): first_na...
Wonted asked 5/6, 2023 at 12:42

3

Solved

I am trying to add a dynamic Meta attribute to all of my Django models using model inheritance, but I can't get it to work. I have a permission that I want to add to all my models like this: class...
Inrush asked 7/4, 2009 at 14:7

2

I want to count amount of Users for same Product models.py class Product(models.Model): pass class User(models.Model): product = models.ForeignKey(Product) age = models.IntegerField(blank=True...
Isherwood asked 13/6, 2019 at 5:0

10

Solved

I have model UserProfile with field avatar = models.ImageField(upload_to=upload_avatar) upload_avatar function names image file according user.id (12.png for example). But when user updates the ...
Crum asked 1/3, 2012 at 19:36

4

Solved

I'm looping through a list of objects and saving. I need the newly generated id or pointer id right after the save but it is None. Here is my code: for category in category_list: saved_categor...

4

Solved

I'm a newbie in Django, so sorry if explanation of problem looks weird. I created a blog app within a Django project. models.py: from django.db import models class Blog(models.Model): title =...
Katabolism asked 16/8, 2018 at 5:22

6

Solved

I have facebook authentication in my website which I use omab / django-social-auth I want to redirect users to another website to make them fill their details. So I want to have users as inactive ...
Paleozoic asked 27/2, 2013 at 21:35

9

Solved

after running "python manage.py syncdb" i gett an error saying "unable to open database file". here is the important part from my settings.py: DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2',...
Var asked 19/7, 2010 at 11:5

3

Solved

Question What is the best way to set a JSONField to have the default value of a new list in django? Context There is a model where one of the fields is a list of items. In the case where there a...
Tidbit asked 15/2, 2017 at 2:47

4

Solved

I install my application in "project/apps/myapp" folder. Both apps and myapp folders have init.py files(Without any of them there is module missing error). Now I've the error: Exception Type: Runt...
Melaniemelanin asked 27/10, 2014 at 15:46

2

Solved

Lets say I have these this base model: class Trackable(PolymorphicModel): uuid = UUIDField(unique=True) created_by = models.ForeignKey(settings.AUTH_USER_MODEL) created_at = models.DateTimeFiel...
Detention asked 1/3, 2015 at 22:27

4

Solved

I have a model currently defined like this: class Category(models.Model): ID = models.AutoField() name = models.CharField() desc = models.CharField() Another model Subcategory has a ForeignKe...
Constellate asked 17/5, 2018 at 8:24

15

Solved

I'm learning Django from Tango with Django but I keep getting this error when I type: python manage.py makemigrations rango python manage.py migrate This is the output: django.db.utils.Integrit...
Smother asked 31/3, 2015 at 16:38

4

Solved

In Django, I have the following model: from django.db import models from django.core.files.base import File import os, os.path class Project(models.Model): video = models.FileField(upload_to="me...
Rameau asked 24/1, 2011 at 21:4

4

Solved

I have a form on my website, that creates an entry in database. So every time when I refresh a page I got this message first: The page that you're looking for used information that you entered. R...
Nolasco asked 4/8, 2012 at 19:22

5

Solved Interesting: ./manage.py makemigrations apps.myapp -> "App 'apps.myapp' could not be found. Is it in INSTALLED_APPS?" ./manage.py makemigrations myapp -> Works. ./manage.py makemigrations...
Grecian asked 24/9, 2016 at 17:54

© 2022 - 2024 — McMap. All rights reserved.