Tuesday, 18 August 2015

Day 6 - creating database in Python django

the code is really easy:

I am going to create class with...

property_name = models.Type(parameters)

so the example below

class album(models.Model):                    #it is starting creating class as a table
    name = models.CharField(max_length=50)      # CharField mean that will be characters in the table
    


The full example below:

class Artist(models.Model):
    name = models.CharField('artist', max_length=50)
    year_formed = models.PositiveIntegerField()

class Album(models.Model):
    name = models.CharField('album', max_length=50)

    artist = models.ForeignKey(Artist)


Next we need to migrate the classes to the database





No comments:

Post a Comment