Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I create Django models automatically?

I’m working on a resume website with Django in which, for the skill section I defined a model as below,

from django.db import models


class Skills(models.Model):
    name = models.CharField(max_length=50)
    level = models.DecimalField(max_digits=3, decimal_places=3)
    def __str__(self):
        return self.name

But, for example, if I add a skill "Python" through admin in this model, I want to add a few slides for the skill, each containing a image and a paragraph, to give detailed information about my skill.

In other words, I want to create a table for each skill I’ll add with columns named image, and description.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there any way I can achieve it?

>Solution :

If one skill can have multiple ‘slides’, you need to create another model with a foreignkey(ManyToOne) to your skills model.

for example:

class Skills(models.Model):
    name = models.CharField(max_length=50)
    level = models.DecimalField(max_digits=3, decimal_places=3)
    def __str__(self):
        return self.name

class SkillDetail(models.Model):
    skill = models.ForeignKey(Skills, on_delete=models.CASCADE)
    image = models.ImageField(upload_to='images/')
    description = models.TextField()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading