Questions tagged [django-model-field]

112 questions
0
votes
1 answer

I can't use the command ' python manage.py makemigrations' in django VSC

I already did 'python manage.py migrations'. Now i want to create '0001_inital.py' file in migrations with the code 'python manage.py makemigrations'. Firstly this is my models.py; from django.db import models class Room(models.Model): #host…
0
votes
0 answers

How to resolve a field path (as passed to the QuerySet.filter method) to the target field in django?

How to resolve a field path like (document__owner__name__contains), as it would be passed to .filter(), to its target field (which here is document.owner.name here) ?
hl037_
  • 3,520
  • 1
  • 27
  • 58
0
votes
2 answers

Why django admin is not reading the __str__ method?

I'm trying to add a str method in my models.py file to my administrative page show me the objects I've register with their own name and not like a 'UserObject(1)' But when I add this method that's what is happening: AttributeError at…
0
votes
1 answer

How to set placeholder for django integerfield

I have a model form: class CaseForm(ModelForm): class Meta: model = Case fields = ["sex", "age"] With corresponding model: class Case(TimeStampedModel): id = models.UUIDField( primary_key=True, unique=True,…
RobMcC
  • 392
  • 2
  • 7
  • 20
0
votes
1 answer

In model my image field is showing blank even though I have inserted the image from html

In model my image field is showing blank even though I have inserted the image from html
0
votes
2 answers

MultiSelectField vs separate model

I'm building a directory of Hospitals and Clinics and as a speciality field I'd like to store the speciality or type of clinic or hospital (like Dermathologist, etc.). However, there are some places, specially big ones, with many different…
0
votes
2 answers

Initialize django ModelForm user field with current logged user

I'm trying to initialize some fields of my NewArticleForm with static data. In particular, I want to set the author field with the current logged user/author, and shouldn't be modifyable. This page is reachable only from logged user, and the…
0
votes
2 answers

How are the names of model items not showing up in DJango Admin?

I'm building a website using python and Django, but when I looked in the admin, the names of the model items aren't showing up. So, the objects that I am building in the admin aren't showing their names. admin.py: from .models import Article,…
0
votes
1 answer

How can I set 'or' in two django model fields

Suppose I have a django model of an Image: from django.db import models class Image(models.Model): ... image = models.ImageField(upload_to='some_place') image_url = models.URLField() ... and I want that a user can upload…
Vijay Soni
  • 197
  • 1
  • 10
0
votes
2 answers

A count of ForeignKey

I have class Team, which means a group of users. And the relation with User is One-to-Many. class Team(models.Model): member = models.ForeignKey(User, null=True, on_delete=models.SET_NULL) But Team may consist of 2 and N members. I think to…
0
votes
1 answer

How to use Reverse Relations in Model Django

Here I'm trying to create 4 Foriegn Keys of DeviceException Table in DeviceControlPolicy Table for individual Device. This DeviceException table will consist 4 Type of Device Exceptions and i am creating individual Columns as foriegn key in…
0
votes
1 answer

Django: Defining 'present_company' from 'company_name' ManytoManyField

I have 2 models, Company and Employee, and defined company history as a ManytoManyField. I am trying to save the present company name of the employee which I get from the company name ManytoManyField. What should be the method to save it? This is…
0
votes
0 answers

My Models info wont appear on new page but it does on the previous one

Within my Django implementation I created a model that would show my information that I stored on the admin in the website. I managed to create the public page to have links of name attribute within the model but when I try to do the same on the…
0
votes
2 answers

Django model field custom validator returned value not saved

I have the following implementation for the phone number custom validation. It does the validation correctly, but the returned value (formatted) is not saved in the model instance. I don't use a custom form and data is entered from admin…
0
votes
1 answer

How to retrieve data from model that current user created and list it for another model's field in django

Let us imagine that I have two models. First model contains curse details and user that created this course class Course(models.Model): course_name = models.CharField(max_length=100, null=False) description =…