Skip to content

Get Started Astro Tutorial — 2. Defining the data model

00:00 / 00:00

2. Defining the data model

Data Model

In the previous step, we created the project and gave it a name.

Now we move to the Model tab and define the structure of our data.

About Data Model

Let's start with the easiest part: the About page where we introduce ourselves.

About page

What content will this page have?

  • A photo.
  • A full name.
  • A short bio.
  • An extended bio.

If we defined it in TypeScript, it would look something like this:

interface About {
  fullname: string;
  picture: media;
  shortBio: string;
  extendedBio: longtext;
}

We're going to create the About entity with the fields we've defined. To do this, click on "Add new model" and name it "About".

Now we start adding fields. Let's begin with the photo:

  • Name: picture
  • Type: media
  • Not a collection—just one photo
  • Validation: this field is required

Next, the name:

  • Name: fullname
  • Type: short text
  • Not a collection—just one name
  • Validation: this field is required

Now the short bio:

  • Name: shortBio
  • Type: short text
  • Not a collection—just one paragraph
  • Validation: this field is required

And finally, the extended bio:

  • Name: extendedBio
  • Type: long text (long text supports Markdown)
  • Not a collection
  • Validation: this field is required

Blog Data Model

Now let's get to the core of our site—we want to display posts, so we’ll define the "Post" entity.

What content will a post have?

  • The title
  • A slug, to identify the post in the URL
  • The publication date
  • The author
  • The post summary
  • A header image
  • The content in markdown (with embedded images, code, etc.)

If it were pseudo-TypeScript, it would look like this:

interface Post {
  title: string;
  slug:string;
  date: Date;
  author: string;
  summary: string;
  image: media;
  content: longtext;
}

We're going to create the Post entity with the fields we've defined. To do this, click on "Add new model" and name it "Post".

And now we start adding fields. First, the title:

  • Name: title
  • Type: short text
  • Not a collection—just one title
  • Validation: this field is required

Next, the slug:

  • Name: slug
  • Type: short text
  • Not a collection, just a single slug
  • Validations: this field is required

Next, the date:

  • Name: date
  • Type: date
  • Not a collection—just one date
  • Validation: this field is required

Now the author:

  • Name: author
  • Type: short text
  • Not a collection—just one author
  • Validation: this field is required

Post summary:

  • Name: summary
  • Type: short text
  • Not a collection—just one summary
  • Validation: this field is required

Header image for the post:

  • Name: image
  • Type: media
  • Not a collection—just one image
  • Validation: this field is required

Finally, the content of the post:

  • Name: content
  • Type: long text (long text supports Markdown)
  • Not a collection
  • Validation: this field is required

Now our structure is complete :)

Next, we'll start entering data.