'How to stop Django inserting null columns for NoSql DB
I user django and mongodb for my project. I want to stop django orm from inserting null columns to DB.
Here is some of my django files:
# models.py
from django.db import models
class Ad(models.Model):
user_id = models.IntegerField()
title = models.CharField(max_length=100)
description = models.CharField(max_length=500)
fee = models.CharField(max_length=20)
phone = models.CharField(max_length=10)
location = models.CharField(max_length=50, default="")
category = models.CharField(max_length=25)
est_rooms = models.CharField(max_length=10)
est_area = models.CharField(max_length=10)
est_age = models.CharField(max_length=10)
# views.py
a = Ad.objects.create(user_id=request.user.id, title=title, description=description, fee=fee, phone=phone, location=location, category=category, est_rooms=est_rooms, est_age=None)
a.save()
For example, if I insert as above although I did not give anything for est_area, it inserts est_area="", but I don't want this. Instead, I want django orm not to insert est_area property. Could anyone help me?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
