Now, let's turn to our non-technical examples. It has used software, web, and mobile development since its foundation. Consider the example of Facebook compared to conventional media outlets like The New York Times, BBC, and the Washington Post.įacebook is a technology company known for its social media platforms such as WhatsApp and Instagram. In your social/models.py file, add the following code for a Like model.Today, most businesses use software as an important part of their operations irrespective of whether or not they operate in the technology domain. Moderation may be an unsolved problem, but we can at least add Like and Comment models. We want our users to be able to like photos that interest them and share constructive feedback in comments. If everything looks good, then congrats! We've got about 1/100th feature parity with Instagram. If you check the media/ directory in your project, you'll see the uploaded photo is stored in there and resized if necessary. Thankfully this isn't our end user interface. If you create a superuser with python manage.py createsuperuser, you should be able to navigate to admin/ when the server is running and create a new photo under "Social > Photos". User ) class CustomUserAdmin (UserAdmin ) : """Custom user admin.""" # social/admin.py """Administration for our social app.""" from django. While we're here, let's add it to the administration panel in social/admin.py: You can now create the model with manage.py makemigrations and manage.py migrate, which will create it in the database! Finally, we also defined a default ordering for photos as well as a magic method for displaying it as a string. Our Photo model extends the BaseModel model, and has some standard fields like who created it, when it was created, and the last time it was edited. This isn't required, and you can make your photos be larger or smaller. Our photo field will automatically resize any uploaded files to be 1200px times 1200px or less, while preserving aspect ratio. We've added two imports from the new imagekit library, ProcessedImageField and ResizeToFit. DateTimeField (auto_now = True ) def _str_ (self ) : return f" " class Meta : """Metadata.""" DateTimeField (auto_now_add = True )ĭate_updated = models. User, verbose_name = "Created By", on_delete =models. # = BaseModel and User = class Photo (BaseModel ) : """A photo posted by a user.""" models import ProcessedImageFieldįrom imagekit. # social/models.py """Models for the social application.""" import uuidįrom django. Let's start our new project by creating a folder djangogram and adding a requirements.txt file with the following contents:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |