GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Tuesday, April 5, 2011

Django - Shell

from django.db import models

# Create your models here.

class Personal(models.Model):
    name = models.CharField(max_length=20)
    city = models.CharField(max_length=20)
    age = models.IntegerField()
    
    def __unicode__(self):
        return self.name

For example, you have models file like the above one, then on python manage.py shell (data is your project)
>>> from data.models import Personal
>>> p = Personal.objects.all()
>>> p = Personal(name='lady gaga', city='new york', age=24)
>>> p.save()     # flush the buffer
>>> p.name = 'Lady Gagah'   #updating
>>> p.save()
Share/Bookmark

1 comment:

  1. what if there is a ImageField in personal. how to save using shell.

    ReplyDelete