Let's say that I have to save a class array in django.how in a particular category? for example. I have books in a class. I want to store thriller books and classrooms in class books. What is the syntax for Django models and database tables?
have you read? Everything has been explained. The answer can actually depend on the database that you are using, though. But assuming that you use classical SQL, how does the ORM work:
1) You define the main model:
class company ( Models.Model): name = models.CharField (Max_length = 100) # Some other fields if needed 2) You define the model that indicates the main model :
Class Employer (model model): name = model.carfield (max_long = 100) company = model.origink (company) # & lt; ----- Relationship here # Some other fields are required if you have comp type company You can use it by using all employers of that company: comp.employer_set all () employer_set The property comes with the name of the Employer class combined with the suffix _set . You can set your own name for this area. You just need to modify the definition of the class of the employer class like: class employer (model. Model): name = model.carfild (max_label = 100) Note # Meditation Company = Model You can now use: comp.employers.all () / Pre> These basics are actually impossible (or at least extremely inefficient) for relational databases to create an array of references in the main model. Although this is not the case if you are using some non-core database such as MongoDB
Comments
Post a Comment