Getting Started note translation from: https://docs.djangoproject.com/en/1.8/topics/
* This note will be presented separately for each module
*migration&managing files&testing in Django
1. Migration's command
The Migrate command is responsible for applying migrations and also for revoking migrations and viewing their status.
Makemigrations creates a new migrations based on changes to the model.
SQLMIGRATE displays the SQL statement for migration.
2. Files in the model
1 from Import Models 2 3 class Car (models. Model):4 name = models. Charfield (max_length=255)5price = models. Decimalfield (max_digits=5, decimal_places=2)6 photo = models. ImageField (upload_to='cars')
In the above model, photo is a file.
1>>> car = Car.objects.get (name="Chevy")2>>>Car.photo3<ImageFieldFile:chevy.jpg>4>>>Car.photo.name5 'cars/chevy.jpg'6>>>Car.photo.path7 '/media/cars/chevy.jpg'8>>>Car.photo.url9 'http://media.example.com/cars/chevy.jpg
3. The Tests in Django
1 fromDjango.testImportTestCase2 fromMyapp.modelsImportAnimal3 4 classanimaltestcase (TestCase):5 defsetUp (self):6Animal.objects.create (name="Lion", sound="Roar")7Animal.objects.create (name="Cat", sound="Meow")8 9 defTest_animals_can_speak (self):Ten """Animals that can speak is correctly identified""" OneLion = Animal.objects.get (name="Lion") ACat = Animal.objects.get (name="Cat") -Self.assertequal (Lion.speak (),'the lion says "Roar"') -Self.assertequal (Cat.speak (),'the cat says "Meow"')
--The End--
Django Module Note "Six"