Django Models

Python manage.py makemigrations

Python manage.py migrate

python manage.py migrate --run-syncdb


Listing 7-12. Django model with custom save() method

class Store(models.Model):
    name = models.CharField(max_length=30)    
    address = models.CharField(max_length=30)
    city = models.CharField(max_length=30)
    state = models.CharField(max_length=2)
        
    def save(self, *args, **kwargs):
        # Do custom logic here (e.g. validation, logging, call third party service)
        # Run default save() method
        super(Store,self).save(*args, **kwargs)



ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

สอนเขียน Python เพื่อใช้ SSH ด้วย Paramiko และ Netmiko แบบรวบรัด

เริ่มพัฒนา Web Application กับภาษา Python ด้วย Django Framework

ตัวอย่างที่น่าสนใจ