Quazer
Quazer

Reputation: 383

ModelAdmin ManyToManyField can be empty?

I have the class Tag with ManyToManyField:

class Tag(models.Model):
    templates = ManyToManyField(Template, related_name='tags')

And TagAdmin class in admin.py

from django.contrib import admin
from . import models

@admin.register(models.Tag)
class TagAdmin(admin.ModelAdmin):
    ...

In django-admin require select at once value for field templates. But I don't want it! How I can use admin without required field templates.

Upvotes: 0

Views: 37

Answers (1)

notanumber
notanumber

Reputation: 6549

It's not entirely clear to me what you're asking for. It seems like you want to create instances of Tag without any templates. If so, you need to update the Tag model to make the templates field optional

class Tag(models.Model):
    templates = ManyToManyField(Template, related_name='tags', null=True, blank=True)

Upvotes: 1

Related Questions