Skip to content

Instantly share code, notes, and snippets.

@jamesperes-zz
Created October 6, 2017 00:42
Show Gist options
  • Save jamesperes-zz/2d087391cebdb756dff97f711034bb3b to your computer and use it in GitHub Desktop.
Save jamesperes-zz/2d087391cebdb756dff97f711034bb3b to your computer and use it in GitHub Desktop.
erro de OO
class TagGeral(models.Model):
tag = models.CharField(max_length=50, verbose_name='Tag secundarias')
class Post(models.Model):
tag = models.ManyToManyField(TagGeral)
tag_lista = models.CharField(max_length=100, blank=True)
def get_tags(self):
tags = self.tag_lista.split(', ')
tag_geral = TagGeral.objects.all()
for i in tags:
if tag_geral.filter(tag=i):
tag_filtered = tag_geral.get(tag__iexact=i)
self.tag.add(tag_filtered)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment