Database Views

16 views
Skip to first unread message

HULUGESH B

unread,
Aug 27, 2019, 10:47:14 AM8/27/19
to Django users
Hi All,


I am facing issues in Django Models:

If connect databse views in models.

It shows less records than actual number of records. Kindly assist me. How to solve. This is not all the time.. sometimes it is correct sometimes not correct.

Jani Tiainen

unread,
Aug 27, 2019, 1:01:58 PM8/27/19
to django...@googlegroups.com
Hi.

You really need to provide more context. Without knowing your data, tables involved in a view. Your model and query you used and query you used to verify wrong (or correct) results it is virtually impossible to help you further.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/29c228cc-295a-487e-a5df-afb1471b8730%40googlegroups.com.

Doddahulugappa.B

unread,
Aug 27, 2019, 2:03:15 PM8/27/19
to django...@googlegroups.com
Thanks for your response.

In Django models.. For example 

class TempUser(models.Model):
    first_name = models.CharField(max_length=100)

    class Meta:
        managed = False
        db_table = "temp_user"


temp_user is database view. 
Now assume select * from temp_user
Gives 5 records 

Same model if i register in admin panel. 
It will show less records than 5. 
Even if i do TempUser.Objects.Count()
It will show less records than 5.

Very rare case it show exactly what view is having otherwise most of the time it fails to show exact records. 
I observed this since many days in 3 to 4 projects of my django



Doddahulugappa.B

unread,
Aug 28, 2019, 1:24:54 AM8/28/19
to django...@googlegroups.com
Thank you. I got it.. Issue with timezone

By default django considering 
TIME_ZONE = 'UTC'
USE_TZ = True

Thats the reason it was showing less records than actual.. 
I changed it local to local time zone name and USE_TZ = False

Its working perfectly.. I also understood that its not only to database views, its also applicable to tables also. 

Kindly make sure to change above two lines in setting according to ur local time zone to render correct records. 

Thank you. 

Reply all
Reply to author
Forward
0 new messages