i wanted to create a tag option for a a music model , well mainly musics accept more than one tag and there are amny kind of genres and tags ,so i wanted to make a ManyToManyField()
that you can set more than 1 value ,also if you tag is not in add it in. to do that i thought maybe can make another CharField()
then adding it to tag_name
:
JavaScript
x
21
21
1
#posts model
2
name = models.CharField(max_length=200)
3
band = models.CharField(max_length=200)
4
release = models.DateTimeField()
5
tag_add = models.CharField(max_length=100)
6
tags = models.ManyToManyField(Tags)
7
#cover = models.ImageField(upload_to='media/image')
8
#file = models.FileField(upload_to='media/audio')
9
10
class Meta(self):
11
ordering = ['release']
12
13
def __str__(self):
14
return self.name
15
16
def get_absolute_url(self):
17
return reverse('pages:music_detail',args=[str(self.id)])
18
19
class Tags(models.Model):
20
tag_name = models.CharField(max_length=100)
21
but i stuck here too ,i really dont know how to add a models field data to another models field ? i would appreciate if you guide me here
Advertisement
Answer
For a user to select more than one tag, they simply have to ctrl
then click on the tags. For Android I suppose it’s long-pressing.
For adding a tag if it’s not in the models, you don’t need a field for that. In the admin, you can just click on the +
sign.