Questions tagged [django-model-field]

112 questions
1
vote
2 answers

Django - model that has a count per CHOICES Field

django 2.1, python 3.6 Let's say I have a set of things ['house_1','house_2',...] and I want to have a model that keeps a count of each item. I'd imagine that it'd look like the following. class Card(models.Model): house_1_count =…
Micah Pearce
  • 1,805
  • 3
  • 28
  • 61
1
vote
1 answer

CharField not saving

I'm a relative django newbie, but I haven't been able to find that this is somewhere else. I setup django in accordance with the djangogirls tutorial and created a model that looks something like this: class Grimmage(models.Model): gStart =…
toby.in.dresden
  • 117
  • 2
  • 11
1
vote
0 answers

Using callable as path attribute of Django's FilePathField?

I have the following model that includes a file upload by a user. def resume_path(instance, filename): # file will be uploaded to MEDIA_ROOT/user_/resume/ return 'user_{0}/resume/{1}'.format(instance.student_user.id,…
cmanbst
  • 179
  • 3
  • 13
1
vote
0 answers

django form "exclude" works, "fields" doesn't

This question almost seems like too much of a hassle to ask, so if I don't provide enough details, I'm sorry. I'm using a bunch of different things in this project so to provide details on all of it would take me half the day. If there's something…
mastachimp
  • 438
  • 3
  • 14
0
votes
1 answer

Changing Year, Month, or Day in a Django model's date field using annotate

I have a Django model MyModel class MyModel(models.Model): """My Model that stores date.""" date = models.DateField() In my API I am receiving a param, review_month I need to get all the entries in MyModel and replace their date's year…
0
votes
0 answers

django model Field for content that could be either a video or an image

I would like to define a django model Field that could be either an image or a video. I Thought about using the image field and modifying the validator to accept also video files. but what should I do with width and height attributes in case the…
piscvau
  • 33
  • 1
  • 3
0
votes
2 answers

I am getting this error django.core.exceptions.FieldError: Unsupported lookup 'icontains' for ForeignKey or join on the field not permitted

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_name = models.CharField(max_length=100) …
0
votes
0 answers

How to change Django model field from Integer to Decimal field for Postgres DB?

I'm trying to change the data type of a Django model field from PositiveBigIntegerField() into DecimalField(). From: quantity=models.PositiveBigIntegerField() To: quantity=models.DecimalField(max_digits=8, decimal_places=2) But when I migrate the…
0
votes
0 answers

can you add hidden field to django orm object?

I am fairly new to django so bear with me. but is it possible to implement something similiar to laravel's hidden array: $hidden = ['password', ] in django? I intend to use it in the same manner as the laravel code, to hide the password field from…
0
votes
2 answers

how to customize django model message for email

I created User model in Django as: email = models.EmailField( verbose_name="Email Address", unique=True, null=True, blank=True) When I try to register user with same email it show message user with this Email Address already exist, how can…
Ayaz Khan
  • 104
  • 1
  • 9
0
votes
0 answers

auth_user table created alongside accounts_user table in postgres(Django)

Using: class User(AbstractBaseUser): pass #models here I added extra fields to my custom user model. This table is created successfully in postgres with absolutely no issues, however, whilst creating a superuser the credentials gets pushed to…
0
votes
1 answer

using django models to map one to many and many to one

I started using django today and am having trouble creating models based off the response of an API call. We can have a Course that gives a list of professors. Though, Professors can also teach multiple courses. I'm not sure how to create a list for…
0
votes
1 answer

How should queryset be set for related fields

I have two models named book and chapter. each book can have many chapters, so models are like: class Book(models.Model): title = models.CharField(max_length=100) class Chapter(models.Model): title = models.CharField(max_length=100) …
0
votes
1 answer

how can I display or return a instance of a django model by using another instance(which is primary key)

views.py I have Wallet class. with fields user and Walletname. When a new user is registered, a new Wallet object is created by signal. What I would like to do is display Walletname of the current logged in user. I tried filtering but I got error…
0
votes
0 answers

Django Sites Framework __str__ representation

I'm experimenting with the Django Site framework. In an UpdateView form, the Site model _str_ representation is self.domain, but I want to use self.name. For example, instead of 'www.test.com', I'd like 'Test, Inc.' to appear. I guess I could…