我可以在“选择”中选择一些选项(django型号)?

发布于 2025-02-13 05:26:20 字数 865 浏览 3 评论 0原文

ID喜欢在页面上制作音乐流派的领域,并且上传音乐用户可以选择哪种音乐音乐,但音乐不仅具有1个单一类型,例如流行音乐,说唱或金属和摇滚。 那么,无论如何是否可以选择多个选择?

from django.db import models

class Mdata(models.Model):
    name = models.CharField(max_length=100)
    artist = models.CharField(max_length=150)
    album = models.CharField(max_length=100)
    nation = models.CharField(max_length=100)
    duration = models.DecimalField(max_digits=4,decimal_places=2)
    released_in = models.DecimalField(max_digits=4,decimal_places=0)
    uploaded_at = models.DateTimeField(auto_now_add=True)
    genre = models.TextField()
    image = models.ImageField(upload_to='images/',blank=True)
    audio = models.FileField(upload_to='audios/')

    def __str__(self):
        return self.name.title()+" by "+self.artist.title()

另外,我读了一个用于音乐页面的模型文件,发现作家使用了2种型号:1个音频轨道,另一个用于图像文件,它比将所有这些都放在1类中更好吗? 我该如何与两种型号合并形式?

id like to make a field for music genres in page and while uploading music users can select what genre music is but a music doesnt have only 1 single genre like pop and rap or metal and rock.
so is there anyway to choose more than one choice?

from django.db import models

class Mdata(models.Model):
    name = models.CharField(max_length=100)
    artist = models.CharField(max_length=150)
    album = models.CharField(max_length=100)
    nation = models.CharField(max_length=100)
    duration = models.DecimalField(max_digits=4,decimal_places=2)
    released_in = models.DecimalField(max_digits=4,decimal_places=0)
    uploaded_at = models.DateTimeField(auto_now_add=True)
    genre = models.TextField()
    image = models.ImageField(upload_to='images/',blank=True)
    audio = models.FileField(upload_to='audios/')

    def __str__(self):
        return self.name.title()+" by "+self.artist.title()

also i read a model file for music page and found out writer had used 2 models :1 for audio track and another one for image file ,is it better than making all of them in 1 class ?
and how can i make a form combined with 2 models?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人问我粥可暖 2025-02-20 05:26:20
choices = (('others', 'Others'),('rap', 'Rap'),('pop' ,'Pop'))
music = models.TextField(choices=choices,default='others')

我记得通过创建列表和使用内置选择参数来选择下拉值,我记得在我的应用程序上做类似的操作。

choices = (('others', 'Others'),('rap', 'Rap'),('pop' ,'Pop'))
music = models.TextField(choices=choices,default='others')

I remember doing something similarly on my app to pick dropdown values by creating a list and using the built in choices parameter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文