You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i am trying to automatically add tags list to the tag field by post save method to copy all the fileld's to tags field.
i tried below which shows success without any exception but the issue is all the fields are added to tags table in admin but not associating the tags to that specific resource tag field.
def save(self, *args, **kwargs):
if not self.id:
# Newly created object, so set slug
self.slug = slugify(self.title)
super(resource, self).save(*args, **kwargs)
def Tag(self):
return ",".join([str(p) for p in self.Tags.all()] )
def _str_(self):
return self.title
i am trying to automatically add tags list to the tag field by post save method to copy all the fileld's to tags field.
i tried below which shows success without any exception but the issue is all the fields are added to tags table in admin but not associating the tags to that specific resource tag field.
[class resource(models.Model):
title=models.CharField(max_length=100)
size=models.CharField( max_length=20, default="")
desc=models.TextField(default="")
file=models.FileField(default="", blank=True)
url= models.URLField(max_length=200, blank=True)
Brand = models.ForeignKey(brand,on_delete=models.CASCADE, default="")
Model = models.ForeignKey(model,on_delete=models.CASCADE, default="")
Categories = models.ForeignKey(category,on_delete=models.CASCADE, default="")
update_at=models.DateField(auto_now=True)
slug=models.SlugField(default="")
Tags = TaggableManager()
def tag_set(sender, instance,*arg, **kwargs):
ans= array_tag(instance)
# print(ans)
mylist = ["firmware", "download", "gsm"]
instance.title='check'
instance.Tags.add(*ans)
post_save.connect(tag_set, sender=resource)
def array_tag(instance):
return [instance.title ,instance.desc,instance.size, instance.Brand.title ,instance.Model.title ,instance.Categories.title]
](url)
i also gave it a try by changing code as below which through below error.
changed this
def tag_set(sender, instance,*arg, **kwargs): ans= array_tag(instance) # print(ans) mylist = ["firmware", "download", "gsm"] instance.title='check' instance.Tags.add(*ans)
to this
def tag_set(sender, instance,*arg, **kwargs): ans= array_tag(instance) # print(ans) mylist = ["firmware", "download", "gsm"] instance.title='check' instance.Tags.add(ans)
and got below error
Cannot add ['tags_check', 'check file', '6G', 'oppo', 'oppoA37', 'china'] (<class 'list'>). Expected <class 'django.db.models.base.ModelBase'> or str.
any help by experts is highly appreciated
The text was updated successfully, but these errors were encountered: