Questions tagged [django-model-field]
112 questions
0
votes
0 answers
Custom __eq__() function for Django field
I need to have a CharField with custom __eq__ function so that when I run model_class.objects.filter(id=something) instead of just checking equality of both strings, my custom __eq__ function should be run. Or is there any other way to implement the…

icyfire
- 1,170
- 8
- 21
0
votes
1 answer
django-models - a non-string type is stored into CharField
I am using Django 1.11 on Python 3, and MySQL 5.7.
Suppose I have a model with a CharField, like so:
class ModelA(models.Model):
ID = models.AutoField(primary_key=True)
a = models.CharField()
And in the shell, I tried doing this:
>>>…

codeandfire
- 445
- 2
- 9
0
votes
1 answer
Exception when swapping a ForeignKey with ManyToMany Field
I am getting the following error after I changed a ForeignKey relation to a ManyToMany relationship.Does update method work on Many to Many ?.
Cannot update model field
(only
non-relations and foreign keys permitted).
Now this happens in the…

James Franco
- 4,516
- 10
- 38
- 80
-1
votes
1 answer
How do I fix Django returning 'self' not defined NameError on queryset filtering of ModelChoiceField?
I have 2 models, Type and Measure. Each Measure object has a typeid ForeignKey field that refers to the id field of a Type object. Each Type is viewed on it's own page where the id is passed through URL.
urls.py
urlpatterns = [
…

MODaly
- 1
- 1
-1
votes
1 answer
how can i resolve ValueError: Field 'cid' expected a number but got ''.?
while performing migration I am getting this error...
(env) PS C:\Users\ashwi\Documents\GitHub\AMCH\AMCH_Recruiter> python manage.py migrate
Operations to perform:
Apply all migrations: Recruiter, admin, auth, contenttypes, sessions
Running…

Ashwin Behera
- 47
- 1
- 7
-1
votes
1 answer
Setting a default value for model fields in Django
I want to create a model in Django with two fields {initial price, current price} .. is there a way in Django to set the default value for the current price field to be the same as the initial price field value?
-2
votes
1 answer
How do I access a model field from a different model? is this possible at all?
suppose I have two models
class Project(models.Model):
project_number = models.Charfield(primary_key=True, max_length=10)
project_title = models.Charfield(max_length=100)
total_cost = models.DecimalField(max_digits=8, decimal_places=2,…