To make a webpage that contains images, videos, texts, how can i creat models. My project is let say a person(john) have tiktok acc, insta acc, his youtube channel etc. My website should show these data so for this how can i creat models.
The first thing you need to do is identify what all the data is that you need to track for each user.
How much experience with Django do you have? How many other Django projects have you built? (Your answers here will help us target our answers for you.)
This is be my first project. I dont have too much experience.
Ok, so if youâve worked through either the official Django Tutorial or the Django Girls tutorial, youâve learned how to build a model and how to create relationships between tables.
From there, youâll want to read the Model field docs to get an idea of what kinds of data you can store in your models. You may want to look specifically at the FileField and ImageField docs to get some ideas.
Beyond that, then itâs just a matter of identifying what the data is you want to store and creating the fields to store them.
What I would suggest is that you trim down your scope for this first iteration. Instead of trying to build everything all at once, pick just one facet of this to get something up and running to minimize the number of different components you may need to code to start. Once youâve gained the knowledge of seeing how all the pieces fit together, then youâll find it a lot easier to add the other components.
Is this correct
Class Person_detail(models.Model):
name = models.CharField(max_length = 20)
profession = models.CharField(max_length = 20)
bio = models.CharFirld( max _length = 150)
Class video(models.Model):
name = models.Charfield(max_length = 20)
videofile = models.File.field( upload _to = âmedia_root_directoryâ)
Class img(models.Model):
name = models.Charfield(max_length = 20)
imgfile = models.Image.field( upload _to = âmedia_root_directoryâ, height_field = â100â, width_field = â100â, max_length = â100â)
Youâve got a fair number of typos in there - Iâll assume are due to retyping it here rather than copy/pasting your actual code.
Assuming the syntax is correct, those could be valid models. But since you havenât really described what your data structures need to be, I canât say whether this will fit your requirements or not.
This leads me back to the more fundamental question - do you know precisely what it is youâre trying to do here? Do you know what data youâre needing to manage, and how that data relates to the other data in your proposed system?
Also, have you come up with your âminimumâ implementation for what you want to do to get started?
There i am just trying to creat table for datas such as videos, image and texts from which i can describe about a person detail.
Youâre still being vague here. âCreate table for data such asâŚâ is just a starting point. You need to identify exactly what data you need to store for a person. You need to have a very clear understanding of what youâre trying to do, and what you need to store in order to accomplish this.
So far I think youâve got a general idea of what you want the end result to look like, but you havenât yet shared what that all means from the perspective of the data. This may be why youâre struggling with creating your models - you may not have figured out what the data is that you need to store, and thatâs what you need to work on next.
Yeah you are right.
Now i am getting clear
Here i want:
A person
For whose i want to store:
His name( first and last) it would be text.
His profession( example, webdeveloper) [ text]
His pp size photo , [ img]
Or say i want to make identycard.
And now i should work for these data. Right.
Cool, ok. Then all those fields would be fields in your Person model. For each of those pieces of data, youâll define a field to hold it.
But since weâre talking about people, thereâs one aspect of this that may affect how you design this. Are these people all âregistered usersâ of your site, in which case they would be associated with the build-in User model, or are they different people?
Yeah, registered user
In that case, youâll want to read the docs on Extending the existing User model, particularly starting from the second paragraph where it starts to talk about a âprofile modelâ.