Skip to content

Instantly share code, notes, and snippets.

@codetombomb
Last active September 29, 2020 18:33
Show Gist options
  • Save codetombomb/411a3cf05146cb8f521a61309df2216b to your computer and use it in GitHub Desktop.
Save codetombomb/411a3cf05146cb8f521a61309df2216b to your computer and use it in GitHub Desktop.
Model example with attributes
from django.db import models
# Create your models here.
# I would like for my Projects model to include the following attributes:
# -Images
# -Summary
# -Link for Video
class Projects(models.Model):
# To create an Image property for a class:
image = models.ImageField(upload_to='project_images/')
# the ImageField property is going to be saved to the image variable. The ImageField property accepts img, jpeg, png, etc.
# upload_to is pointing to the location that you would like to save the images. If the file does not exist, when the object is persisted with the image, the directory will be created and the file will be saved to that dir.
#summary
summary = models.CharField(max_length=250)
#same kind of thing here with the summary except we are specifying that the field type is goign to be CharField. You can specify how many characters you would like to save per Object.summary
# Link to video
video_link = models.CharField(max_length=150)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment