having trouble with django models

40 views
Skip to first unread message

Mukul Agrawal

unread,
Dec 16, 2017, 11:01:15 AM12/16/17
to Django users
Hello, I am newbie to django. I was trying my hand on models. When i used the below code in models.py, "timestamp" and "updated" are not able visible on admin site. Is something wrong with the code? 

'''
from django.db import models

# Create your models here.
class RestaurantLocation(models.Model):
    name             = models.CharField(max_length=120)
    location         = models.CharField(max_length=120, null=True, blank=True)
    category         = models.CharField(max_length=120, null=True, blank=True)
    timestamp        = models.DateTimeField(auto_now=False,auto_now_add=True)
    updated          = models.DateTimeField(auto_now=True, auto_now_add=False)
    
'''

Mike Dewhirst

unread,
Dec 16, 2017, 4:20:02 PM12/16/17
to django...@googlegroups.com, Mukul Agrawal
On 16/12/2017 10:06 PM, Mukul Agrawal wrote:
> Hello, I am newbie to django. I was trying my hand on models. When i
> used the below code in models.py, "timestamp" and "updated" are not
> able visible on admin site. Is something wrong with the code?

It looks OK to me. Have you included them in your admin.py ...
        fieldsets = (
            ('RestaurantLocation', {
                'fields': (
                    'name',
                    'location',
                    'category',
                    'timestamp',
                    'updated',
                    ),
                }
            ),
        )


>
> '''
> from django.db import models
>
> # Create your models here.
> class RestaurantLocation(models.Model):
>     name             = models.CharField(max_length=120)
>     location         = models.CharField(max_length=120, null=True,
> blank=True)
>     category         = models.CharField(max_length=120, null=True,
> blank=True)
>     timestamp        =
> models.DateTimeField(auto_now=False,auto_now_add=True)
>     updated          = models.DateTimeField(auto_now=True,
> auto_now_add=False)
> '''
> --
> 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
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a80a81c1-fade-42a0-b8f5-20638541a5bf%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/a80a81c1-fade-42a0-b8f5-20638541a5bf%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Daniel Roseman

unread,
Dec 16, 2017, 5:26:40 PM12/16/17
to Django users
This is expected behaviour. You've set them to be populated automatically on create and update. So there's no need to be modifiable via the admin.

--
DR.

Mike Dewhirst

unread,
Dec 17, 2017, 3:44:51 AM12/17/17
to django...@googlegroups.com
> On 17/12/2017 9:26 AM, Daniel Roseman wrote:
>> This is expected behaviour. You've set them to be populated automatically on create and update. So there's no need to be modifiable via the admin.

Of course!

However, if you want to see the fields you have to mention them among
other fields you wish to display as indicated below and - based on
Daniel's advice above - you might need to include ...

readonly_fields = ['timestamp', 'updated']
Reply all
Reply to author
Forward
0 new messages