Django Module Note "Six"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.