S
S
Sergey Nizhny Novgorod2016-06-02 02:08:25
Django
Sergey Nizhny Novgorod, 2016-06-02 02:08:25

How to display editing for ManyToManyFiled model in admin panel?

I'm making a tagging system for the site now.
There are two models (Article and Tag).

class Article(models.Model):
    article_categore = models.CharField(max_length=200, default=1, choices=Article_CHOICES, help_text="Категория статья - для фильтра", verbose_name="Категория статьи")
    article_body = models.TextField(help_text="Полное описание текста", verbose_name="Тело статьи")   

#Таг для статьи

class Tag(models.Model):
  name = models.CharField(max_length = 25, default=1)
  main = models.ManyToManyField(Article, related_name='tags')

It is required that in the Django Admin, when editing an article, you can add tags to it. Those. output manytomany editor to Tag. And I can't do this.
For example, if there were not ManyTomany but Forenkey, then everything could be displayed like this.
class TagType(admin.TabularInline):
     model = Tag
     max_num = 3
 admin.site.register(Tag, TagType)

class ArticleType(admin.ModelAdmin):
    model = Article
    fields = ['article_categore', 'article_body']
    nlines = [
         TagType,
     ]
admin.site.register(Article, ArticleType)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Nizhny Novgorod, 2016-06-02
@Terras

In short, I've been digging all day. Bottom line:
1) This thing is not officially supported by Django.
2) There are various frauds with bringing two models into a third one (intermediary) for tuning, but there is also some kind of sodomy there.
3) There are speculative API-based solutions that do shuttle races and prescribe and create models. But it also does not inspire confidence.
Generally!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question